I have a dataframe:
df = pd.DataFrame([
{'a': 1, 'b': 'abc'},
{'a': 1, 'b': 'def'},
{'a': 2, 'b': 'abc'},
{'a': 2, 'b': 'def'},
{'a': 2, 'b': 'ghi'},
])
And I would like to get the resulting dataframe as so:
df = pd.DataFrame([
{'a': 1, 'b': ['abc', 'def']},
{'a': 2, 'b': ['abc', 'def', 'ghi']}
])
I suspect something like :
df_new = df.groupby(df['a'])
but I need to somehow "aggregrate" strings into one cell (as a list). How do I achieve this?