Search code examples
python-3.xalpha-vantage

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


This is the program for the stock prediction to be simply printed...

  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'])

I get this error...

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'

Since that didn't work, I tried getting a little more technical with it...

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()

I get these errors...

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

How can I improve my program so that I don't receive these errors? None of these programs are bad syntax wise. Thank you to anyone that can help.


Solution

  • You need to install pandas. If you're just using pip, you can run pip install pandas if you are using conda to manage your envs you can use conda install pandas.


    Glad it worked. According to this meta overflow post: What if I answer a question in a comment? I am posting my comment as an answer so you can mark the question as answered.