renaming columns after group by and sum in pandas dataframe

You cannot rename it, because it is index. You can add as_index=False for return DataFrame or add reset_index:

pdf_chart_data1=pdf_chart_data.groupby('sell', as_index=False)['value'].sum()
                              .rename(columns={'sum':'valuesum','sell' : 'selltime'})

Or:

pdf_chart_data1=pdf_chart_data.groupby('sell')['value'].sum()
                          .reset_index()
                          .rename(columns={'sum':'valuesum','sell' : 'selltime'})

df = df.groupby('col1')['col1'].count()
df1= df.to_frame().rename(columns={'col1':'new_name'}).reset_index()

Tags:

Pandas