I have a pandas dataframe
import pandas as pd
df = pd.DataFrame({'c1': ['a', 'b', 'b'], 'c2': [1, 2, 2], 'c3': [[100], [200], [100]]})
df
that is
c1 c2 c3
0 a 1 [100]
1 b 2 [200]
2 b 2 [100]
Now when I try to concatenate column c3
after grouping by on c1
, I get desired result
In [40]: df.groupby('c1').agg({'c3': 'sum'})
Out[40]:
c3
c1
a [100]
b [200, 100]
But if I try to groupby on both c1
and c2
, that is
df.groupby(['c1', 'c2']).agg({'c3': 'sum'})
I get an error saying ValueError: Function does not reduce
.
Why is it that?
pandas 0.23.1
it working nice. – jezrael Jul 9 '18 at 8:15pandas 0.22.0
– kampta Jul 9 '18 at 8:18