I recently started working with python and I am now working with API request. I need to convert dataframe to a dictionary of lists nested in the list.
How to convert df
:
data = {'x': ['15.0', '42.2','43.4','89.0','45.8'],
'y': ['10.1', '42.3','43.5','5.0','45.9']
}
df = pd.DataFrame (data, columns = ['x','y'])
To dictionary of lists nested in the list
{
"Points": [
[15.0, 10.1], [42.2, 42.3], [43.4, 43.5], [89.0, 5.0], [45.8, 45.9]
]
}
I tried using df.to_dict
with list as a orient parameter but the result is 2 long lists of x and y instead of many pair-lists.
Probably trivial problem for python users, thanks for help in advance!