i have a Data Frame Like the following:
Year Month S_ID Channel_Name Interaction Doc_ID Feed_ID
2018 2 67 WhiteCoats 1 152 5776
2018 2 67 WhiteCoats 4 152 5776
2018 2 67 WhiteCoats 4 152 6046
2018 2 67 Beats 4 152 6117
2018 2 84 Beats 4 27261 6286
2018 2 84 Beats 1 9887 6286
I have grouped the data with the columns: Year,Month,S_ID,Channel_Name,Interaction
code:
df.groupby(['Year','Month',S_ID,Channel_Name,Interaction])
but i want a new column with list of dict the column Doc_ID,Feed_ID
Result Frame Should Look Like:
Year Month S_ID Channel_Name Interaction Dictionary
2018 2 67 WhiteCoats 1 [{'Doc_id':152,'Feed_ID':5776}]
2018 2 67 WhiteCoats 4 [{'Doc_id':152,'Feed_ID':5776}]
2018 2 67 Beats 4 [{'Doc_id':152,'Feed_ID':6117}]
2018 2 84 Beats 4 [{'Doc_id':27261,'Feed_ID':6286},{'Doc_id':9887,'Feed_ID':6286}]
Presently i am able to create only a list:
df.groupby(['Year','Month',S_ID,Channel_Name,Interaction])[['Doc_id','Feed_id']].apply(lambda x: x.values.tolist())
But how to Create a list of Dict?