Streamlit: Pandas CategoricalIndex not supported

Created on 4 Sep 2019  路  3Comments  路  Source: streamlit/streamlit

Summary

Pandas supports a _Categorical Index_ datatype. When using st.write(dataframe), if the dataframe contains some categorical data an error is generated.

Steps to reproduce

Create a dataframe with a Categorical Index. For example: uses pd.cut to segment existing numerical data (https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.cut.html)
This is a snippet that takes a _median_income_ column and segments it (from https://github.com/ageron/handson-ml/blob/master/02_end_to_end_machine_learning_project.ipynb row 22)
df['income_cat'] = pd.cut(df['median_income'], bins=[0., 1.5, 3.0, 4.5, 6., np.inf], labels=[1, 2, 3, 4, 5])

Expected behavior:

No error. The dataframe is shown in the UI.

Actual behavior:

NotImplementedError: Dtype category not understood. st.write(df['income_cat']) NotImplementedError: Can't handle <class 'pandas.core.indexes.category.CategoricalIndex'> yet. st.write(df['income_cat'].value_counts())

Is this a regression?

Not that I know

Debug info

  • Streamlit version: Streamlit v0.45.0
  • Python version: 3.7.4
  • Using Conda? PipEnv? PyEnv? Pex?
  • OS version: MacOs 10.14.6
  • Browser version: Chrome 76.0.3809.100

Additional information

If needed, add any other context about the problem here.

dataframe enhancement

Most helpful comment

Workaround for now:

st.write(df.astype('object'))

All 3 comments

Workaround for now:

st.write(df.astype('object'))

I think @kantuni's Arrow work will address this

Related #453

Was this page helpful?
0 / 5 - 0 ratings

Related issues

isConic picture isConic  路  3Comments

tconkling picture tconkling  路  3Comments

nthmost picture nthmost  路  3Comments

randyzwitch picture randyzwitch  路  3Comments

thingumajig picture thingumajig  路  3Comments