StreamlitAPIException: ("Expected bytes, got a 'int' object", 'Conversion failed for column xxx with type object')

Was playing around with some charting with the Altair library. Everything was going well until I hit this error when using some of the sample code.

Currently running streamlit v 1.9.0
Python v 3.8.13
macOS

Offending code:

movies_df = pd.read_json(vega_data.movies.url)
...Lots more code here, but nothing relevant
st.altair_chart(alt.Chart(movies_df).mark_point(filled=True)

StreamlitAPIException: (“Expected bytes, got a ‘int’ object”, ‘Conversion failed for column xxx with type object’)

To fix this, I had to add the following to my ~/.streamlit/config.toml file (you might have to create it)

[global] dataFrameSerialization = “legacy”

Some research suggests that this is the issue:

and that streamlit 0.85.0 was the initial version impacted by this.

This seems to be related to this topic as well.

Hello,

I was facing the same problem, and I read in some places that it is a bug version that started in the 0.85.0 version.

A workaround that worked for me was to convert DataFrame cells to strings with df.astype(str).

test = df_selected_team.astype(str)
st.dataframe(test)

Maybe it can work for you too.