I'm trying to combine multiple rows of a dataframe into one row, with the columns with different values being combined in a list. There are multiple columns with different values.
The df.groupby('a')['b'].apply(list)
works well if only 1 column ('b' in this instance) has to be made to a list, but I can't figure out how to do it for multiple columns.
Dataframe:
a b c d
0 1 b 1 first
1 1 b 2 second
2 2 c 1 third
3 2 c 2 fourth
4 2 c 3 fifth
Prefered dataframe post operation:
a b c d
0 1 b [1, 2] [first, second]
1 2 c [1, 2, 3] [third, fourth, fifth]
Is there an easy way to do this?