st.dataframe does not support multiindex dataframe styler formatting.
See original GitHub issueI’m trying to apply a dictionary of formats via the pandas styler to a multiindex dataframe. But it throws and error.
You can see the error if you pip install yahooquery
and streamlit run
the below script
import streamlit as st
from yahooquery import Ticker
data = Ticker("ORSTED.CO").balance_sheet(frequency="annual")
st.header("Raw Data")
st.dataframe(data)
def get_default_format(data):
format_dict = {}
for column in data.columns:
if data[column].dtype == "int64":
format_dict[column] = "{0:,.0f}"
elif data[column].dtype == "float64":
format_dict[column] = "{0:,.2f}"
else:
format_dict[column] = "{0:}"
return format_dict
st.header("Dataframe Index dropped and decimal symbol format applied")
data_reset_index = data.reset_index()
format_dict = get_default_format(data_reset_index)
st.dataframe(data_reset_index.style.format(format_dict))
st.header("Dataframe Index NOT dropped and decimal symbol format applied")
format_dict = get_default_format(data)
st.dataframe(data.style.format(format_dict))
and the error is
RuntimeError: Found unexpected row header "{'type': 'th', 'is_visible': True, 'value': 0, 'display_value': 0, 'id': 'level1_row0', 'class': 'row_heading level1 row0'}"
Traceback:
File "c:\repos\private\awesomestreamlit\.venv\lib\site-packages\streamlit\ScriptRunner.py", line 324, in _run_script
exec(code, module.__dict__)
File "C:\repos\private\awesomestreamlit\scripts\issues\issue_dataframe.py", line 28, in <module>
st.dataframe(data.style.format(format_dict))
File "c:\repos\private\awesomestreamlit\.venv\lib\site-packages\streamlit\__init__.py", line 152, in wrapped_method
return method.__get__(dg)(*args, **kwargs)
File "c:\repos\private\awesomestreamlit\.venv\lib\site-packages\streamlit\DeltaGenerator.py", line 88, in wrapped_method
return method(self, *args, **kwargs)
File "c:\repos\private\awesomestreamlit\.venv\lib\site-packages\streamlit\DeltaGenerator.py", line 887, in dataframe
set_data_frame, "dataframe", elementWidth=width, elementHeight=height
File "c:\repos\private\awesomestreamlit\.venv\lib\site-packages\streamlit\DeltaGenerator.py", line 392, in _enqueue_new_element_delta
rv = marshall_element(msg.delta.new_element)
File "c:\repos\private\awesomestreamlit\.venv\lib\site-packages\streamlit\DeltaGenerator.py", line 884, in set_data_frame
data_frame_proto.marshall_data_frame(data, delta.data_frame)
File "c:\repos\private\awesomestreamlit\.venv\lib\site-packages\streamlit\elements\data_frame_proto.py", line 55, in marshall_data_frame
_marshall_styles(proto_df.style, df, styler)
File "c:\repos\private\awesomestreamlit\.venv\lib\site-packages\streamlit\elements\data_frame_proto.py", line 76, in _marshall_styles
display_values = _get_custom_display_values(df, translated_style)
File "c:\repos\private\awesomestreamlit\.venv\lib\site-packages\streamlit\elements\data_frame_proto.py", line 188, in _get_custom_display_values
raise RuntimeError('Found unexpected row header "%s"' % cell)
Issue Analytics
- State:
- Created 4 years ago
- Comments:8
Top Results From Across the Web
pandas multiindex column styler - python - Stack Overflow
How do I write the styler so that all the nmem columns have thousand separators {:,} , 'pct_fem' are percentages to two decimal...
Read more >Style Pandas Dataframe Like a Master - Towards Data Science
The basic idea behind styling is to leverage visual aids like color and format, in order to communicate insight more efficiently.
Read more >Styling — pandas 0.25.1 documentation
This is a property that returns a Styler object, which has useful methods for formatting and displaying DataFrames. The styling is accomplished using...
Read more >st.dataframe - Streamlit Docs
If 'data' is a pandas.Styler, it will be used to style its underlying DataFrame. Streamlit supports custom cell values and colors. (It does...
Read more >Dataframe Styling using Pandas [Guided Walkthrough] | Tables
Learn how to use the pandas python library to style dataframes & add conditional formatting, bar charts, & more in this guided walkthrough.....
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
Is there any progress concerning this so far?
This project has been stalled for a while, but I’ve resumed working on it recently.