I have a df where each row has a code that indicates a department.
On the other hand, I have a dictionary in which each code corresponds to a region name (a region is constituted of multiple departments).
I thought of a loop to put the value in a new column that indicates the region.
Here is what I thought would work:
for r in df:
dep = r["dep"].astype(str)
r["region"] = dep_dict.get(dep)
But the only thing I get is "string indices must be integers". Do you people know how could I make it work ? Or if I should take a totally different route (like joining) ?
Thanks ! 🙏
rinfor r in dfis a column header (which is a string, in your case). So,r["dep"]is an attempt to index a string with a string.