提问人:Kalev Maricq 提问时间:1/21/2019 更新时间:2/9/2023 访问量:5934
通过 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 密钥?
答:
6赞
lehiester
1/21/2019
#1
源代码显示了 DataReader 工厂函数如何将其传递给 Quandl 读取器:
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()
因此,请尝试将其传递给 DataReader,并带有以下参数:access_key
pdrquandl=pdr.DataReader('WIKI/'+ticker,'quandl',start,end,access_key=qkey)
0赞
Marcell Kovacs
5/26/2020
#2
对 quandl 的处理方法略有不同
import quandl
quandl.ApiConfig.api_key = "API-KEY"
aapl = quandl.get("WIKI/TICKER", start_date="YEAR-MONTH-DAY", end_date="YEAR-MONTH-DAY")
0赞
cryptomamy
2/6/2021
#3
配置
- MAC操作系统
- VS 代码
- 蟒蛇 3.x
方法
- 运行以下代码:
import pandas_datareader.data as pdr
api_key = [YOUR_API_KEY]
pdrquandl = pdr.DataReader("WIKI/TICKER", 'quandl', start_date, end_date, api_key)
上一个:生成数据的最有效排序算法
下一个:具有缺失值的加权协方差矩阵
评论