在 Python 中使用 Alpha Vantage 编写简单的股票预测服务。我收到这个错误

Programming a simple Stock prediction service with Alpha Vantage in Python. I get this error

这是简单打印股票预测的程序...

  from alpha_vantage.timeseries import TimeSeries
    # Your key here
    key = 'yourkeyhere'
    ts = TimeSeries(key)
    aapl, meta = ts.get_daily(symbol='AAPL')
    print(aapl['2020-22-5'])

我收到这个错误...

Traceback (most recent call last):
  File "C:/Users/PycharmProjects/AlphaVantageTest/AlphaVantageTest.py", line 7, in <module>
    print(aapl['2020-22-5'])
KeyError: '2020-22-5'

由于那没有用,我尝试了更多的技术知识...

from alpha_vantage.timeseries import TimeSeries
from alpha_vantage.techindicators import TechIndicators
from matplotlib.pyplot import figure
import matplotlib.pyplot as plt

# Your key here
key = 'W01B6S3ALTS82VRF'
# Chose your output format, or default to JSON (python dict)
ts = TimeSeries(key, output_format='pandas')
ti = TechIndicators(key)

# Get the data, returns a tuple
# aapl_data is a pandas dataframe, aapl_meta_data is a dict
aapl_data, aapl_meta_data = ts.get_daily(symbol='AAPL')
# aapl_sma is a dict, aapl_meta_sma also a dict
aapl_sma, aapl_meta_sma = ti.get_sma(symbol='AAPL')


# Visualization
figure(num=None, figsize=(15, 6), dpi=80, facecolor='w', edgecolor='k')
aapl_data['4. close'].plot()
plt.tight_layout()
plt.grid()
plt.show()

我收到这些错误...

Traceback (most recent call last):
  File "C:/Users/PycharmProjects/AlphaVantageTest/AlphaVantageTest.py", line 9, in <module>
    ts = TimeSeries(key, output_format='pandas')
  File "C:\Users\PycharmProjects\AlphaVantageTest\venv\lib\site-packages\alpha_vantage\alphavantage.py", line 66, in __init__
    raise ValueError("The pandas library was not found, therefore can "
ValueError: The pandas library was not found, therefore can not be used as an output format, please install manually

如何改进我的程序,以免收到这些错误? None 这些程序的语法很糟糕。感谢任何可以提供帮助的人。

您需要安装 pandas。如果你只是使用 pip,你可以 运行 pip install pandas 如果你使用 conda 来管理你的环境,你可以使用 conda install pandas.


很高兴它起作用了。根据这个元溢出post:What if I answer a question in a comment? 我post将我的评论作为答案,以便您可以将问题标记为已回答。