Bhargava Macha
Bhargava Macha

Reputation: 87

Unable to convert a Pandas Dataframe to dictionary

I have a variable, x:

print(type(x)) gives:
<class 'pandas.core.series.Series'>
print(x) gives:
date
2020-04-09    3.00
2020-04-10    2.51
2020-04-11    2.57
2020-04-12    2.41
2020-04-13    2.27
2020-04-14    2.23
2020-04-15    2.10
2020-04-16    1.94
2020-04-17    1.86
2020-04-18    1.69
Name: ML, dtype: float64

I am trying to convert it into a dictionary like this:

{'2020-04-09':3.00,'2020-04-10':2.51, '2020-04-11':2.57....}

Tried a lot of things but nothing worked. Printing x.list gives:

[3.   2.51 2.57 2.41 2.27 2.23 2.1  1.94 1.86 1.69]

Any help appreciated!

Upvotes: 0

Views: 35

Answers (1)

V. Ayrat
V. Ayrat

Reputation: 2719

x.to_dict()

should give you what you want

Upvotes: 2

Related Questions