Summary
I am trying to make a datetime slider but I am getting an error:
KeyError: <class ‘pandas._libs.tslibs.timestamps.Timestamp’>
KeyError: <class 'pandas._libs.tslibs.timestamps.Timestamp'>
File "/Users/indapa/miniconda3/lib/python3.9/site-packages/streamlit/scriptrunner/script_runner.py", line 557, in _run_script
exec(code, module.__dict__)
File "pages/Production_Over_Time.py", line 21, in <module>
date_range = st.sidebar.slider('Select Date Range',
File "/Users/indapa/miniconda3/lib/python3.9/site-packages/streamlit/elements/slider.py", line 152, in slider
return self._slider(
File "/Users/indapa/miniconda3/lib/python3.9/site-packages/streamlit/elements/slider.py", line 227, in _slider
data_type = SUPPORTED_TYPES[type(value[0])]
My code is:
solar_file = Path(__file__).parent.parent / "solar_production.csv"
data = pd.read_csv(solar_file, index_col=0)
data['Time'] = pd.to_datetime(data['Time'], errors='coerce')
data = data[pd.notna(data['Time'])]
start_date = data['Time'].min()
end_date = data['Time'].max()
# create a date slidebar to select date range
date_range = st.sidebar.slider('Select Date Range', start_date, end_date, (start_date, end_date))
st.write('You selected:', date_range)
I am not sure what the issue is. Perhaps I should not be calling to_datetime on my pandas dataframe?