Pandas categories support not implemented
See original GitHub issueSummary
Streamlit seems to be unable to render Pandas series or dataframes which contain categorical elements, throwing a NotImplementedError: Dtype category not understood.
error.
Steps to reproduce
- Create a streamlit file with contents of
import streamlit as st
import pandas as pd
s = pd.Series(["a","b","c","a"], dtype="category")
st.write(s)
- Run the file with streamlit and view the served result in the browser
Expected behavior:
s
is rendered as a table or datatable.
Actual behavior:
An error along the lines of
NotImplementedError: Dtype category not understood.
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/__init__.py", line 352, in write dataframe(arg) # noqa: F821
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/__init__.py", line 126, in wrapped_method return method(dg, *args, **kwargs)
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/DeltaGenerator.py", line 79, in wrapped_method return method(self, *args, **kwargs)
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/DeltaGenerator.py", line 789, in dataframe set_data_frame, "dataframe", elementWidth=width, elementHeight=height
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/DeltaGenerator.py", line 317, in _enqueue_new_element_delta rv = marshall_element(msg.delta.new_element)
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/DeltaGenerator.py", line 786, in set_data_frame data_frame_proto.marshall_data_frame(data, delta.data_frame)
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/elements/data_frame_proto.py", line 50, in marshall_data_frame _marshall_table(df_data, proto_df.data)
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/elements/data_frame_proto.py", line 288, in _marshall_table _marshall_any_array(pandas_array, proto_table.cols.add())
File "/home/caspar/src/streamlit-test/.venv/lib/python3.7/site-packages/streamlit/elements/data_frame_proto.py", line 329, in _marshall_any_array raise NotImplementedError("Dtype %s not understood." % pandas_array.dtype)
Is this a regression?
no
Debug info
- Streamlit version:
Streamlit, version 0.47.4
- Python version:
Python 3.7.4
- Using Conda? PipEnv? PyEnv? Pex?
Pip
withvirtualenv
- OS version:
Ubuntu 18.04.3 LTS
running in WSL. - Browser version: Firefox,
69.0.2 (64-bit)
Additional information
Seems related to #47.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:8
- Comments:12 (2 by maintainers)
Top Results From Across the Web
Using pandas categories properly is tricky... here's why
Pandas category errors, categories turn to strings, category merges change datatypes, empty groups when groupby on cats.
Read more >Categorical data — pandas 1.5.2 documentation
All values of categorical data are either in categories or np.nan . Order is defined by the order of categories , not lexical...
Read more >Pandas Categorical data type not behaving as expected
I want to make the code column an ordered variable of type Categorical after the df creation as below. import pandas as pd...
Read more >Using The Pandas Category Data Type
Introduction to pandas categorical data type and how to use it.
Read more >Type Support in Pandas API on Spark — PySpark 3.3.1 ...
These kind of pandas specific data types below are not currently supported in pandas API on Spark but planned to be supported. pd.Timedelta....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Any ETA on when Streamlit will support displaying categorical variables?
Workaround from a related issue: st.write(df.astype(‘object’))