Pandas groupby to to_csv
Try doing this: week_grouped = df.groupby(‘week’) week_grouped.sum().reset_index().to_csv(‘week_grouped.csv’) That’ll write the entire dataframe to the file. If you only want those two columns then, week_grouped = df.groupby(‘week’) week_grouped.sum().reset_index()[[‘week’, ‘count’]].to_csv(‘week_grouped.csv’) Here’s a line by line explanation of the original code: # This creates a “groupby” object (not a dataframe object) # and you store it in the … Read more