How to implode(reverse of pandas explode) based on a column

If you want the “opposite” of explode, then that means bringing it into a list in Solution #1. You can also join as a string in Solution #2: Use lambda x: x.tolist() for the ‘APPLICABLE_DAYS’ column within your .agg groupby function: df = (df.groupby([‘NETWORK’,’config_id’]) .agg({‘APPLICABLE_DAYS’: lambda x: x.tolist(),’Case’:’mean’,’Delivery’:’mean’}) .rename({‘Case’ : ‘Avg_Cases’,’Delivery’ : ‘Avg_Delivery’},axis=1) .reset_index()) df … Read more