Here is a sample dataframe -
df = pd.DataFrame({'ID': ['a1', 'a1', 'a1', 'a1', 'b2', 'b2', 'b2'],
'Price': [15, 12, 10, 10, 36, 34, 36]})
ID Price
0 a1 15
1 a1 12
2 a1 10
3 a1 10
4 b2 36
5 b2 34
6 b2 36
Here is the expected output -
df.groupby('ID').agg({'Price': ['last', 'last_count']})
ID Price_last Price_last_count
a1 10 2
b2 36 2
I need to be able to perform the 'last_count' operation in the agg.