group by pandas to list 1

group by pandas to list

df.groupby('a')['b'].apply(list)

Here is what the above code is Doing:
1. Grouping the dataframe by column ‘a’
2. Applying the function list to column ‘b’
3. The result is a series with index ‘a’ and values ‘b’

Similar Posts