Group by and aggregate rows into list of series or dicts in Pandas

Try this

compact_df =  df.groupby('ID').apply(lambda group: group.to_dict(orient='records'))

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top