通过 Pandas Data-Reader 获取 Quandl 数据

Getting Quandl Data via Pandas Data-Reader

我在使用 pandas-datareader 从 Quandl 导入数据时遇到问题。这是我尝试过的代码(使用真正的 API 键):

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)

我在 运行 时收到以下错误消息:

>>> 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'

我错过了什么?如何提供 API 密钥?

source 显示了 DataReader 工厂函数如何将其传递给 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()

因此尝试使用 access_key 参数将其传递给 DataReader:

pdrquandl=pdr.DataReader('WIKI/'+ticker,'quandl',start,end,access_key=qkey)

稍微不同的 quandl 方法

import quandl 
quandl.ApiConfig.api_key = "API-KEY"
aapl = quandl.get("WIKI/TICKER", start_date="YEAR-MONTH-DAY", end_date="YEAR-MONTH-DAY")

我用过这个并且有效:

pdrquandl = pdr.DataReader("WIKI/TICKER", 'quandl', start_date, end_date,api_key = [YOUR_API_KEY])