Python Pandas Dictionary With Numpy Arrays
I have a pandas df like the following: import pandas as pd import numpy as np data = np.random.rand(10,2) data array([[0.88095214, 0.62363749], [0.99251732, 0.97059244],
If need list
s:
You need transpose first and then use parameter orient='list'
:
d = df.T.to_dict('list')
Or use zip
:
d = dict(zip(df.index, df.values.tolist()))
If need numpy array
s:
d = dict(zip(df.index, df.values))
Post a Comment for "Python Pandas Dictionary With Numpy Arrays"