How to get Bitcoin price using Python

1 min readPandasDataFrameDataData GatheringDates
7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

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("https://api.coingecko.com/"\
                          "api/v3/coins/bitcoin/ohlc"\
                          "?vs_currency=usd&days=30")

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

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

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

# We plot the close price with labels and title
btc_prices.close.plot(figsize=(5,3),
                 title="Bitcoin prices last 30 days",
                 xlabel="Date",
                 ylabel="in USD", 
                 grid=True)
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.

7-Day Challenge

Land Your First Data Science Job

A proven roadmap to prepare for $75K+ entry-level data roles. Perfect for Data Scientist ready to level up their career.

Build portfolios that hiring managers love
Master the Python and SQL essentials to be industry-ready
Practice with real interview questions from tech companies
Access to the $100k/y Data Scientist Cheatsheet

Join thousands of developers who transformed their careers through our challenge. Unsubscribe anytime.

Free Newsletter

Master Data Science in Days, Not Months 🚀

Skip the theoretical rabbit holes. Get practical data science skills delivered in bite-sized lessons – Approach used by real data scientist. Not bookworms. 📚

Weekly simple and practical lessons
Access to ready to use code examples
Skip the math, focus on results
Learn while drinking your coffee

By subscribing, you agree to receive our newsletter. You can unsubscribe at any time.