StreamlitAPIException: Expected bytes, got a 'datetime.datetime' object

Hi everybody
I’m trying to use a dataframe created with pandas from an uploaded excel file but I get this error:

StreamlitAPIException: ("Expected bytes, got a 'datetime.datetime' object", 'Conversion failed for column alc with type object')

Traceback:
File "C:\Users\User\app.py", line 56, in <module>
    st.dataframe(df)

I tried to exclude the datetime dtype by both of these two codes separately:

    df = df.select_dtypes(exclude=['datetime64'])

and

    df = df.select_dtypes(exclude=['datetime64[ns]'])

and I put them after this code:

df = pd.read_excel(uploaded_file, engine='openpyxl')

but still get the same error.
Here is the link to the excel file.

I don’t understand what you are trying to achieve, your data does not contain timestamps.

df = pd.read_excel("data.xlsx")
df.info()

Otherwise, please show us your full code.


EDIT:
I think the object types are the problem.
This should work:

df = pd.read_excel("data.xlsx")
df[["ethgp", "alc", "smokenum"]] = df[["ethgp", "alc", "smokenum"]].astype('string')
st.dataframe(df)
1 Like

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