python - 我从 Quandl 检索股票数据时哪里出错了?

标签 python api dataframe stock quandl

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/

相关文章:

ios - 解析 - Linkedin Connect

mysql - 什么存储系统用于实时消息传递?

python - 如何在 pandas 数据帧中选择最小值并保存我的字符串数据

python - Pandas Dataframe 分成 session

python - 如何在 pyautogui 库中使用波斯语文本

python - 通过匹配字典值来查找列表中字典的定义键的值

python - 给定范围内的数字如果循环python

javascript - Youtube API - 处理已被 Youtube 删除的视频

apache-spark - pySpark DataFrames 聚合函数与 SciPy

python - 使带有循环的Python代码块更快