In order to "concatenate" a few rows to 1 list with groupby in Pandas, I can do this:
df = pd.DataFrame({'A': [1,1,2,2,2,2,3],'B':['a','b','c','d','e','f','g']})
df = df.groupby('A')['B'].apply(list)
I will get:
A
-------------------
1 [a, b]
2 [c, d, e, f]
3 [g]
I want to do the same with agg:
f = {"B":[list]}
df = df.groupby('A').agg(f)
that gives errors, any idea?
Thanks,