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')

File "C:\Users\User\", line 56, in <module>

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

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


    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")

Otherwise, please show us your full code.

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')
1 Like

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