I have a data frame which has been grouped by 'hour'. I want to use a for loop which loops through each group and creates a data frame for each group. The code I'm using at the moment only creates a data frame for the last group that it iterates through. Any suggestions on how I can get it to work properly?
for name, group in data.groupby('hour'):
d = {'group_' + str(name) : group}
You're overwriting your object each time you want this:
d = {}
for name, group in data.groupby('hour'):
d['group_' + str(name)] = group
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With