Skip to content Skip to sidebar Skip to footer

Pandas Groupby With Agg Not Working On Multiple Columns

I'm trying to merge multiple columns, each into a list based on a group by in pandas. Below is the code I'm using grouped_df = df.groupby(['d_id', 'time']).agg({'d_name': lambda x:

Solution 1:

Use a single argument instead of three

{'d_name': lambda x: tuple(x), 'ver': lambda x: tuple(x), 'f_name': lambda x: tuple(x)}

Post a Comment for "Pandas Groupby With Agg Not Working On Multiple Columns"