marktilbrook
marktilbrook

Reputation: 83

How would I plot this as a line graph?

I have this data below. I was wondering how I would plot it. This is a dataframe and the first column is the index and the second column holds a timestamp(left number) and then the price. This is only showing the first 5 rows but the dataframe is actually (366, 1). I am not sure how to split the data up so I can make a line chart out of it.

             prices
0   [1577836800000, 1.011314677267319]
1   [1577923200000, 1.048537268947032]
2   [1578009600000, 0.9541815075748614]
3   [1578096000000, 0.9551243387141036]
4   [1578182400000, 0.9450787078323388]

Upvotes: 0

Views: 83

Answers (1)

rftr
rftr

Reputation: 1275

You can convert the column prices to a list by tolist() and store the result in another DataFrame. The result can be plotted with the plot() method of pandas.DataFrame:

import pandas as pd

# df = your dataframe
pd.DataFrame(df["prices"].tolist(), columns=["timestamp", "price"]).plot(x="timestamp")

Result:

enter image description here

Upvotes: 4

Related Questions