How to set group by column-name as column instead of index?(Pandas)

Question:

I have a dataframe:

grouped_df = df.groupby("DATE").sum()

The dataframe looks like:

enter image description here

The group by column DATE is shown as index here. I want the column DATE to be a separate column rather than index.

The condition is that grouped_df['DATE'] should display the data instead of an error.

Asked By: Atom Store

||

Answers:

You can use

grouped_df = df.groupby("DATE", as_index=False).sum()
# or
grouped_df = df.groupby("DATE").sum().reset_index()
Answered By: Ynjxsjmh