Resolved: Dataframe to dictionary with list of items 0 By Isaac Tonny on 18/06/2022 Issue Share Facebook Twitter LinkedIn Question: I have this Dataframe: df = key value 0 1 kpi1 1 1 kpi2 2 1 kpi3 3 2 kpi4 4 2 kpi5 And I am trying to create a dictionary where for the same key, there’s a list of values, like this: d = {'1': ['kpi1', 'kpi2', 'kpi3'], '2': ['kpi4', 'kpi5']} I have tried to use df.apply but I couldn’t find a solution. Do you have some idea? Answer: Try this: df.groupby('key')['value'].apply(list).to_dict() Result: {1: ['kpi1', 'kpi2', 'kpi3'], 2: ['kpi4', 'kpi5']} If you have better answer, please add a comment about this, thank you! apply dataframe dictionary python