Home > Software engineering >  Problem with a column in my groupby new object
Problem with a column in my groupby new object

Time:05-04

so I have a dataframe and I made this operation:

df1 = df1.groupby(['trip_departure_date']).agg(occ = ('occ', 'mean'))

The problem is that when I try to plot, it gives me an error and it says that trip_departure_date doesn't exist!

I did this:

df1.plot(x = 'trip_departure_date', y = 'occ', figsize = (8,5), color = 'purple')

and I get this error:

KeyError: 'trip_departure_date'

Please help!

CodePudding user response:

Your question is similar to this question: enter image description here

df1_agg = df1.groupby(['trip_departure_date'],as_index=False).mean()

Or if you only want to aggregate the occ column:

df1_agg = df1.groupby(['trip_departure_date'],as_index=False)['occ'].mean()

enter image description here

df1_agg.plot(x = 'trip_departure_date', y = 'occ', figsize = (8,5), color = 'purple')

enter image description here

  • Related