Home > OS >  Python Pandas how to create a chart?
Python Pandas how to create a chart?

Time:12-16

I'm newbie in Python and I need create a chart using datas: date and price.

My object has dict:

{'2022-06-15': 0.06544, '2022-06-16': 0.05908, '2022-06-17': 0.05925, '2022-06-18': 0.05497, '2022-06-19': 0.05961, '2022-06-20': 0.0596, '2022-06-21': 0.06003, '2022-06-22': 0.05787, '2022-06-23': 0.06119, '2022-06-24': 0.06154, '2022-06-25': 0.06228, '2022-06-26': 0.06099, '2022-06-27': 0.06008, '2022-06-28': 0.05873, '2022-06-29': 0.05827, '2022-06-30': 0.05773, '2022-07-01': 0.05582, '2022-07-02': 0.05575, '2022-07-03': 0.05595, '2022-07-04': 0.05862, '2022-07-05': 0.05846}

You can see that keys are dates and values are prices.

myObj = list[0]
data = pd.DataFrame([myObj.prices])

print(data) shows: `

   2022-06-15  2022-06-16  2022-06-17  ...  2022-12-12  2022-12-13  2022-12-14
0     0.06544     0.05908     0.05925  ...     0.04991     0.05155     0.05162

`

How I can create a chart using these datas? Thank you for help!

CodePudding user response:

Try:

d = {'2022-06-15': 0.06544, '2022-06-16': 0.05908, '2022-06-17': 0.05925, '2022-06-18': 0.05497, '2022-06-19': 0.05961, '2022-06-20': 0.0596, '2022-06-21': 0.06003, '2022-06-22': 0.05787, '2022-06-23': 0.06119, '2022-06-24': 0.06154, '2022-06-25': 0.06228, '2022-06-26': 0.06099, '2022-06-27': 0.06008, '2022-06-28': 0.05873, '2022-06-29': 0.05827, '2022-06-30': 0.05773, '2022-07-01': 0.05582, '2022-07-02': 0.05575, '2022-07-03': 0.05595, '2022-07-04': 0.05862, '2022-07-05': 0.05846} 
s = pd.Series(d)
s.index = pd.to_datetime(s.index)
s.plot()

Output:

enter image description here

CodePudding user response:

I think you could get a Series() and then use plot():

data.T[0].plot()
  • Related