0

I am trying to plot the price data I took from the CoinGecko API. To get the data itself, I used this command:
mbrp = coingecko.get_coin_market_chart_range_by_id("bitcoin","usd","1577836800","1609459200")["prices"]
The output of that command looks like this:
[[1577836800000, 7195.153895430029],[1577923200000, 7193.7546679601],...,[1609459200000, 29022.41839530417]]
Where the first column (1577836800000) is the UNIX date of the data and the second column is the price (7195.153895430029). I didn't know what to do to make this data plottable, so I tried to plot the data directly like this:
mbrpdf = pandas.DataFrame(mbrp)
mbrpdf.plot()
As I expected this approach did not work. I suspect this is because I haven't removed the outer brackets of the output and the UNIX time column. My question is, how do I remove the outer brackets and the first column?

Thank you in advance.

1 Answer 1

1

pd.Series's index can be the x axis, and it's values show as y axis .

alist = [[1577836800000, 7195.153895430029],[1577923200000, 7193.7546679601],[1609459200000, 29022.41839530417]]
df = pd.DataFrame(alist, columns=['ts', 'price'])
df['date'] = pd.to_datetime(df['ts'], unit='ms')
obj = df.set_index('date')['price']
obj.plot()
Sign up to request clarification or add additional context in comments.

1 Comment

Works perfectly! Thank you

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.