I have a pandas dataframe:
| Reference | timestamp | sub_reference | datatype_indicator | figure |
|---|---|---|---|---|
| REF1 | 2022-09-01 | 10 | A | 23.6 |
| REF1 | 2022-09-01 | 48 | B | 25.8 |
| REF1 | 2022-09-02 | 10 | A | 17.4 |
| REF1 | 2022-10-01 | 10 | A | 23.6 |
| REF1 | 2022-10-01 | 48 | B | 25.8 |
| REF1 | 2022-10-02 | 10 | A | 17.4 |
| REF2 | 2022-09-01 | 10 | A | 23.6 |
| REF2 | 2022-09-01 | 48 | B | 25.8 |
| REF2 | 2022-09-02 | 10 | A | 17.4 |
| REF2 | 2022-10-01 | 11 | A | 23.6 |
| REF2 | 2022-10-01 | 47 | B | 25.8 |
| REF2 | 2022-10-02 | 10 | A | 17.4 |
| REF3 | 2022-09-01 | 10 | A | 23.6 |
| REF3 | 2022-09-01 | 48 | B | 25.8 |
| REF3 | 2022-09-02 | 10 | A | 17.4 |
| REF3 | 2022-10-01 | 11 | A | 23.6 |
| REF3 | 2022-10-01 | 47 | B | 25.8 |
| REF3 | 2022-10-02 | 10 | A | 17.4 |
I need to group the data by 'Reference' and the month in 'timestamp' to produce an aggregated value of 'figure' for the reference/month..
I am trying the below code, but receive TypeError: unhashable type: 'Series'
dg = df1.groupby([
pd.Grouper('reference'),
pd.Grouper(df1['timestamp'].dt.month)
]).sum()
dg.index = dg.index.strftime('%B')
print(dg)