Convert dataframe into dictionary
Or use dict(zip(...))
:
>>> cols = ["Length","Width","Height","Pid"]
>>> items_dic = dict(zip(df['Pid'],df[cols].values.tolist()))
>>> items_dic
{20: [4.8, 4.3, 4.3, 20.0], 21: [4.8, 4.3, 4.3, 21.0], 22: [6.0, 5.6, 9.0, 22.0], 23: [8.75, 5.6, 6.6, 23.0], 24: [6.0, 5.16, 6.6, 24.0]}
>>>
Set parameter drop=False
in DataFrame.set_index
, because default parameter drop=False
move column to index:
cols = ["Length","Width","Height","Pid"]
items_dic = data[cols].set_index('Pid', drop=False).T.to_dict('list')
print (items_dic)
{20: [4.6, 4.3, 4.3, 20.0],
21: [4.6, 4.3, 4.3, 21.0],
22: [6.0, 5.6, 9.0, 22.0],
23: [8.75, 5.6, 6.6, 23.0]}