Save groupby() data in a csv file – Pandas

You either need to set index=True:

df.to_csv('res.csv', index=True, header=True)

or you can reset the index before saving using:

df.reset_index().to_csv('res.csv', index=None, header=True)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top