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],
Solution 1:
If need lists:
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 arrays:
d = dict(zip(df.index, df.values))
Share
Post a Comment
for "Python Pandas Dictionary With Numpy Arrays"
Post a Comment for "Python Pandas Dictionary With Numpy Arrays"