3

I am checking this thread already, but somehow it is not working.

I currently have a dataframe with two columns:

enter image description here

When I check the column types I get:

Datum        datetime64[ns]
MIPS                float64

So now I want to groupby the day and the hour:

df.groupby([df['Datum'].dt.day, df['Datum'].dt.hour])['MIPS'].sum().reset_index()

But I get the following error:

ValueError: cannot insert Datum, already exists

Is it because he cannot create a grouped dataframe with two times the same name? How can I avoid that?

PV8
  • 5,799
  • 7
  • 43
  • 87

1 Answers1

2

You can rename both Series for avoid MultiIndex with same names:

df.groupby([df['Datum'].dt.day.rename('Day'), 
            df['Datum'].dt.hour.rename('Hour')])['MIPS'].sum().reset_index()
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252