Hide None in st.dataframe

Is there a way to hide the None words in pandas dataframe without the need to replace the null value with empty string?

My code is:

df = df.style.background_gradient(cmap='Blues', axis=None).

which produces:

If I replaced the null value with empty strings, the above code will not work due to a mixture of datatypes. However, I would like to hide the None in the empty cells. Thank you!

1 Like

Hey @camole,

Unfortunately, there isn’t a built-in way to automatically hide None via st.dataframe, but this would be a great enhancement request – feel free to post this here so our product and engineering teams can take a look!

Also, I did stumble upon this solution in this thread – not sure if this would work for your specific use case but might be worth giving it a shot

# table.py
import pandas as pd
import streamlit as st

df = pd.read_csv("example.csv", header=0)
df = df.style.highlight_null(props="color: transparent;") 
st.dataframe(df)
2 Likes

Thank you!

1 Like

For anyone landing on this page: as of v1.30.0 at least this solution unfortunately doesn’t seem to work (referenced by someone else on v1.31.0 here).

1 Like