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/”, line 379, in _run_script
exec(code, module.dict)File “/mount/src/602_final/”, line 67, in
choose_dataset = call_data(selected_stock)File “/mount/src/602_final/”, line 62, in call_data
ntdoy_df = fetch_stock_data(“NTDOY”, MY_KEY, 2007)File “/mount/src/602_final/”, line 40, in fetch_stock_data
df[“timestamp”] = pd.to_datetime(df[“timestamp”])File “/home/adminuser/venv/lib/python3.9/site-packages/pandas/core/”, line 3893, in getitem
indexer = self.columns.get_loc(key)File “/home/adminuser/venv/lib/python3.9/site-packages/pandas/core/indexes/”, line 3798, in get_loc
raise KeyError(key) from err

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.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.