I have a dataframe like:
ID Sim Items 1 0.345 [7,7] 2 0.604 [2,7,3,8,5] 3 0.082 [9,1,9,1] I want to form a pivot_table by:
df.pivot_table(index ="ID" , columns = "Items", values="Sim") To do that, I have to extract list elements in items column and repeat the ID,Sim values for each unique elements in row_list. To be as:
ID Sim Items 1 0.345 7 2 0.604 2 2 0.604 7 2 0.604 3 2 0.604 8 2 0.604 5 3 0.082 9 3 0.082 1 pivot table :
7 2 3 8 5 1 9 1 0.345 - - - - - - 2 0.604 0.604 0.604 0.604 0.604 3 - - - - - 0.082 0.082 Is there any pythonic approach for that? Or any suggestions?