Fetch Bitcoin Data Information through Pandas DataReader
Asked Answered
S

3

5

I am wanting to ask if Pandas DataReader may be used to extract Bitcoin information from blockchain.com ?

I am aware we may use it together with Alpha Vantage API Key to extract stocks through:

import pandas as pd
import pandas_datareader as dr
reader = dr.DataReader('AAPL', 'av-daily', start = '2020-08-01', end = '2020-08-05', api_key = '')
print(reader)

But may this same style of function/code be used to extract Bitcoin data? I know of one method but am not a big fan of it:

cc = CryptoCurrencies(key='', output_format='pandas')
btc, meta_data = cc.get_digital_currency_daily(symbol='BTC', market='CNY')
print(btc)

I am pretty new to coding and BTC so would appreciate something straightforward if possible, thank you !

Shing answered 13/9, 2020 at 9:29 Comment(0)
A
6

Querying Bitcoin prices with pandas_datareader should be straightforward:

import pandas_datareader as pdr
btc_data = pdr.get_data_yahoo(['BTC-USD'], 
                          start=datetime.datetime(2018, 1, 1), 
                          end=datetime.datetime(2020, 12, 2))['Close']

Results:

Symbols     BTC-USD
Date    
2018-01-01  13657.200195
2018-01-02  14982.099609
2018-01-03  15201.000000
2018-01-04  15599.200195
2018-01-05  17429.500000
...     ...
2020-11-29  18177.484375
2020-11-30  19625.835938
2020-12-01  18802.998047
2020-12-02  19201.091797
2020-12-03  19445.398438
Asinine answered 17/12, 2020 at 16:49 Comment(1)
As of Aug 2021, Pandas DataReader 0.9.0, this apparently doesn't work anymore. I'm looking for new ways to use DataReader to get BTC daily prices.Distaste
P
4
from pandas_datareader import data
start_date = '2021-01-01'
end_date = '2021-05-01'

btc_price= data.DataReader('BTC-USD','yahoo',start_date,end_date);
Pentagon answered 2/9, 2021 at 1:59 Comment(0)
H
0

A way around:

pip install yfinance 

Code (you can change 'BTC-USD' to 'AAPL'):

import yfinance as yf
import datetime
btc = yf.download('BTC-USD', start=datetime.datetime(2018, 1, 1), end=datetime.datetime(2020, 12, 2))
print(btc.head())
Heaver answered 7/9, 2023 at 17:3 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.