I have a pandas Dataframe df and I want to Group by text column with aggregation of:
- Stack the english_word and return the list
- Sum the count column
Now I only can do either making the english_word list or sum the count column. I try to do that, but it return error. How to do both of that aggregation?
In simple, what I want:
text
saya eat chicken
english_word
[eat,chicken]
count
2
df.groupby('text', as_index=False).agg({'count' : lambda x: x.sum(), 'english_word' : lambda x: x.list()})
This is the example of df:
df = pd.DataFrame({'text': ['Saya eat chicken', 'Saya eat chicken'],
'english_word': ['eat', 'chicken'],
'count': [1,1]})