I have a df in python with different cities.
I am trying to create a df for each city.
So wrote this code in python and it works. It does what I need. But i was wondering if there is any over way to create the name of each df in a different way rather than using
globals()\["df\_"+str(ciudad)\] = new_grouped_by
If I try this:
"df\_"+str(ciudad) = new_grouped_by
Give me this error: SyntaxError: can't assign to operator
Any tips/suggestions would be more than welcome!
def get_city():
for ciudad in df["Ciudad"].unique():
#print (ciudad)
grouped_by = df.groupby('Ciudad')
new_grouped_by=[grouped_by.get_group(ciudad) for i in grouped_by.groups]
globals()["df_"+str(ciudad)] = new_grouped_by
get_city()