Reputation: 31
I am trying to get the value of Bitcoin from yahoo finance using pandas data reader, and then save this data to a csv file. Where is the error here, and how do I fix it?
import pandas as pd
import pandas_datareader.data as web
start = dt.datetime(2017, 1, 1)
end = dt.datetime(2019, 11, 30)
df = web.DataReader('BTC', 'yahoo', start, end)
df.to_csv('BTC.csv')
print(df.head())
This was coded in spyder, python 3.7 if it is relevant...
Upvotes: 3
Views: 4718
Reputation: 379
I received the 'Keyerror 'Date' when using pandas datareader' error and found two errors in my script that fixed the issue:
Hope this helps!
Upvotes: 2
Reputation: 89557
This should work. Use 'BTC-USD' stock/security value:
import pandas as pd
import pandas_datareader.data as web
import datetime as dt
start = dt.datetime(2017, 1, 1)
end = dt.datetime(2019, 11, 30)
df = web.DataReader('BTC-USD', 'yahoo', start, end)
df.to_csv('BTC.csv')
print(df.head())
or
df = web.get_data_yahoo('BTC-USD', start, end)
Upvotes: 2