Using dataframe_explorer to filter dataframe which has datetime object values

Summary

Iam using dataframe_explorer from streamlit_extras Module for filtering a dataframe which contains a datetime object that is formatted (โ€œ%d/%m/%Y %H:%M:%Sโ€) but when i run the code the time columns is formatted to (โ€œ%Y/%m/%d %H:%M:%Sโ€)
and the filter options are also working properly , i even tried to converting into a pandas datetime object, df1[โ€œTimeโ€]=pd.to_datetime(filtered_df1[โ€œTimeโ€], format=โ€œ%d/%m/%Y %H:%M:%Sโ€) and when i give input in the filter column the last row is not visible unless in reload the code

Steps to reproduce

@st.cache_data()
def update_data(_df1,_time_formatted,_count,_component_names,column_names):
_df1.loc[len(_df1)] = [_time_formatted, _count, _component_names]
def filter(column_names):
with st.sidebar:
st.subheader(โ€œFilter Service Down Time Historyโ€)
filtered_df1 = dataframe_explorer(df1)
return filtered_df1
if name =โ€œmainโ€:
time1 = datetime.datetime.now()
time_formatted = time1.strftime(โ€œ%d/%m/%Y %H:%M:%Sโ€)
update_data(df1,time_formatted, len(inactive_components), component_names, column_names)
df1[โ€œTimeโ€] = pd.to_datetime(df1[โ€œTimeโ€], format=โ€œ%d/%m/%Y %H:%M:%Sโ€)
filtered_df, filtered_df1 = filter(column_names)

Expected behavior:
i want to be able to filter the data with the Time column and there shouldnt be any rows missing

Actual behavior:
when i run the code the time columns is formatted to (โ€œ%Y/%m/%d %H:%M:%Sโ€)
and the filter options are also working properly and when i give input in the filter column the last row is not visible unless in reload the code

Debug info

  • Streamlit version: Streamlit, version 1.22.0
  • Python version: Python 3.11.2
  • Using PyEnv - Pycharm
  • OS version:
  • Browser version:

Hi @saitharun_gunasekar

Thanks for your question. It may be helpful to the community if the code snippet is a working example that reproduces the problem that you are encountering. Sharing the appโ€™s code in its entirety (with library imports and the corresponding data used by the app) would definitely help.

Based on provided information, hereโ€™s what I would do to approach this problem:

  • Check to see if deleting @st.cache_data() would resolve the missing rows. Thus, experiment with the placement of the cache statement so that it caches static data while not caching dynamically updated data.
  • In regards to the date-time formatting, perhaps you can post-process the filtered dataframe to the desired date-time format

Hope this helps!

Best regards,
Chanin

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