gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 02:01:19 26 4
gpt4 key购买 nike

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 和 import quandl。然后你可以像上面那样设置api_key属性。

关于python - 从 Quandl 检索股票数据哪里出错了?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55644542/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com