I am having trouble using pandas-datareader to import data from Quandl. Here is the code that I have tried (with a real API key):
import pandas_datareader.data as pdr
from datetime import date
start=date(1970,1,1)
end=date.today()
ticker='F'
qkey=[My API Key]
pdr.QUANDL_API_KEY=qkey
QUANDL_API_KEY=qkey
pdrquandl=pdr.DataReader('WIKI/'+ticker,'quandl',start,end)
pdrquandl=pdr.DataReader('WIKI/'+ticker,'quandl',start,end,api_key=qkey)
I get the following error messages when I run this:
>>> pdrquandl=pdr.DataReader('WIKI/'+ticker,'quandl',start,end)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python37\lib\site-packages\pandas_datareader\data.py", line 379, in DataReader
session=session, api_key=access_key).read()
File "C:\Python37\lib\site-packages\pandas_datareader\quandl.py", line 54, in __init__
raise ValueError('The Quandl API key must be provided either '
ValueError: The Quandl API key must be provided either through the api_key variable or through the environmental variable QUANDL_API_KEY.
>>> pdrquandl=pdr.DataReader('WIKI/'+ticker,'quandl',start,end,api_key=qkey)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: DataReader() got an unexpected keyword argument 'api_key'
What am I missing? How do I provide the API key?
The source shows how the DataReader factory function passes it to the Quandl reader:
elif data_source == "quandl":
return QuandlReader(symbols=name, start=start, end=end,
retry_count=retry_count, pause=pause,
session=session, api_key=access_key).read()
So try passing it to DataReader with the access_key
argument:
pdrquandl=pdr.DataReader('WIKI/'+ticker,'quandl',start,end,access_key=qkey)