ValueError: The Quandl API key must be provided either through the api_key variable or through the environmental variable QUANDL_API_KEY.
我正在尝试从 Quandl 检索一些简单的股票数据。我已经在下面的示例代码中输入了实际的 API key 而不是 x,但我仍然收到错误。我错过了什么吗?
import datetime as dt
import matplotlib.pyplot as plt
from matplotlib import style
import pandas as pd
import pandas_datareader.data as web
style.use('ggplot')
symbol = 'AAPL'
api_key = 'x'
start = dt.datetime(2015, 1, 1)
end = dt.datetime.now()
df = web.DataReader(symbol, 'quandl', start, end, api_key)
print(df.head())
最佳答案
来自quandl docs :
AUTHENTICATION The Quandl Python module is free but you must have a Quandl API key in order to download data. To get your own API key, you will need to create a free Quandl account and set your API key.
After importing the Quandl module, you can set your API key with the following command:
quandl.ApiConfig.api_key = "YOURAPIKEY"
因此您需要 pip install 并导入 quandl
。然后您可以像上面一样设置 api_key
属性。
关于python - 我从 Quandl 检索股票数据时哪里出错了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55644542/