In Pandas 1.1.4, I am receiving a DataError: No numeric types to aggregate when using an ExpandingGroupby.
Example dataset:
tmp = pd.DataFrame({'col1':['a','b','b','c','d','d'], 'col2': ['red','red','green','green','red','blue']})
print(tmp)
col1 col2
a red
b red
b green
c green
d red
d blue
This works:
tmp.groupby('col1').agg(lambda x: ','.join(x))
And this works:
tmp.groupby('col1').expanding().agg('count')
But this returns an error:
tmp.groupby('col1').expanding().agg(lambda x: ','.join(x))
DataError: No numeric types to aggregate
There is no conceptual reason this shouldn't work, and there are several references online to people using custom functions within an ExpandingGroupby.
There is obviously no reason that this should need to be a numeric, especially given that the count works with the non-numeric column. What is happening here? If this can't be done natively for whatever reason, how can I do it manually?