Considering I have the following tmax_period dataframe:
ID Element Data_Value
Date
2005-01-01 USW00014853 TMAX 56
2005-01-01 USC00200228 TMAX 150
2005-01-01 USC00207320 TMAX 150
2005-01-01 USC00207308 TMAX 150
2005-01-01 USC00200230 TMAX 122
DatetimeIndex(['2005-01-01', '2005-01-02', '2005-01-03', '2005-01-04',
'2005-01-05', '2005-01-06', '2005-01-07', '2005-01-08',
'2005-01-09', '2005-01-10',
...
'2014-12-22', '2014-12-23', '2014-12-24', '2014-12-25',
'2014-12-26', '2014-12-27', '2014-12-28', '2014-12-29',
'2014-12-30', '2014-12-31'],
dtype='datetime64[ns]', name='Date', length=3650, freq=None)
How can I group rows by month and day and apply max function to Data_Value column, so I can later build a plot with 365 datapoints? I tried to do the following:
tmax_period.groupby(by=[period.index.month, period.index.day])['Data_Value'].max()
but I got an "AssertionError: Grouper and axis must be same length" error.
EDIT: adding the result of tmax_period.head().to_dict()
as asked in the comments:
{'Data_Value': {Timestamp('2005-01-01 00:00:00'): 122},
'Element': {Timestamp('2005-01-01 00:00:00'): 'TMAX'},
'ID': {Timestamp('2005-01-01 00:00:00'): 'USC00200230'}}