How to get Bitcoin price using Python

1 min

Here is the simplest way I found to retrieve Bitcoin price using Python and the pandas library.

Installing pandas

pip install pandas
python 2.7
pip3 install pandas
python 3.x

Getting Bitcoin prices

# We import the Pandas library
import pandas as pd

# We perform an API call against the coingecko api
# and get back BTC coin prices.
btc_prices = pd.read_json(""\

# We rename the columns to human readable colnames
btc_prices.columns = ["date","open", 
                      "high", "low", 

# We format the date from UNIX to a Human Readable Format
btc_prices["date"] = pd.to_datetime(btc_prices["date"],

# We set the date column as index
btc_prices.set_index("date", inplace=True)

# We plot the close price with labels and title
                 title="Bitcoin prices last 30 days",
                 ylabel="in USD", 
How to get Bitcoin prices.

As we can see the Bitcoin prices are saved under the btc_prices variable.

Here you are ! you now know how to get Bitcoin prices using the pandas library.