'KeyError: 'Date' while running Streamlit on Google Colab with Ngrok

So, I'm following this tutorial and in it the code ran successfully but when i try to run it, it throws this error:

    Traceback (most recent call last):
  File "/usr/local/lib/python3.7/dist-packages/streamlit/scriptrunner/script_runner.py", line 443, in _run_script
    exec(code, module.__dict__)
  File "/content/app.py", line 12, in <module>
    df = pdr.get_data_yahoo(user_input, start, end)
  File "/usr/local/lib/python3.7/dist-packages/pandas_datareader/data.py", line 80, in get_data_yahoo
    return YahooDailyReader(*args, **kwargs).read()
  File "/usr/local/lib/python3.7/dist-packages/pandas_datareader/base.py", line 253, in read
    df = self._read_one_data(self.url, params=self._get_params(self.symbols))
  File "/usr/local/lib/python3.7/dist-packages/pandas_datareader/yahoo/daily.py", line 161, in _read_one_data
    prices["Date"] = to_datetime(to_datetime(prices["Date"], unit="s").dt.date)
  File "/usr/local/lib/python3.7/dist-packages/pandas/core/frame.py", line 3458, in __getitem__
    indexer = self.columns.get_loc(key)
  File "/usr/local/lib/python3.7/dist-packages/pandas/core/indexes/base.py", line 3363, in get_loc
    raise KeyError(key) from err
KeyError: 'Date'

The web app does run and shows the title and the ticker but doesn't show the rest of the code which will give the information about the dataset. But throws an error instead. My code:

%%writefile app.py
import streamlit as st
from pandas_datareader import data as pdr
from datetime import datetime

st.title('Stock Prediction')
#start = '2000-01-03'
start = datetime(2000, 1, 3)
#end = '2021-04-30'
end = datetime(2021, 4, 30)

user_input = st.text_input("Enter Stock Ticker", 'AXISBANK')
df = pdr.get_data_yahoo(user_input, start, end)

# Describe the data
st.subheader('Data from 2000 - \'21')
st.write(df.describe())

I dont know what am i doing wrong, been stuck on it for a day know. Help please.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source