Date Time Format Error

Good Morning!
I am trying to deploy an app. The links work fine when using the local and external links, however when trying to deploy I keep receiving an error for the Date time Format as posted below. The code was actually working fine, and after having the website open for 10 minutes while writing my analysis it stopped working and I received an error. I am using the most recent versions of python and streamlit. How do I fix this. It appears like theres no error in the code

Error Message: ```
File “/home/adminuser/venv/lib/python3.9/site-packages/streamlit/script_runner.py”, line 379, in _run_script
exec(code, module.dict)File “/mount/src/602_final/project_web.py”, line 67, in
choose_dataset = call_data(selected_stock)File “/mount/src/602_final/project_web.py”, line 62, in call_data
ntdoy_df = fetch_stock_data(“NTDOY”, MY_KEY, 2007)File “/mount/src/602_final/project_web.py”, line 40, in fetch_stock_data
df[“timestamp”] = pd.to_datetime(df[“timestamp”])File “/home/adminuser/venv/lib/python3.9/site-packages/pandas/core/frame.py”, line 3893, in getitem
indexer = self.columns.get_loc(key)File “/home/adminuser/venv/lib/python3.9/site-packages/pandas/core/indexes/base.py”, line 3798, in get_loc
raise KeyError(key) from err

https://github.com/maggiekimbis/602_final/tree/main
https://projectwebpy-2ytvfgfipw7ivspysipmaq.streamlit.app/

Hi @maggiekimbis

Looking at your code on lines 38-39:

df = pd.read_csv(io.StringIO(r.decode('utf-8')))
df = pd.DataFrame(df)

It seems that the one on line 39 is not needed. Can you see if deleting this helps.

The error is on the line

df["timestamp"] = pd.to_datetime(df["timestamp"])

where the specific exception is a KeyError when trying to get the index of a column label. The problem here is there is no column "timestamp". Check the spelling of the timestamp column; maybe it’s 'time_stamp' or even 'datetime'. Read this explanation for more information.

Two things:

  1. You may want to use some manner of validation on your request.
    r = requests.get(DAILY_ENDPOINT).content
    You’re grabbing something from the interwebs, and sometimes that goes wrong.
  2. Consider using caching so you aren’t unnecessarily re-retrieving the data.

If I were to to take a wild guess as to what’s happening: you are making repeated calls to that API and getting rate-limited.