Say a sales manager opens your Streamlit dashboard on Monday morning. The table shows 97150.0 and -0.021, and she has to work out on her own which regions missed their targets. The numbers are right, but the table makes her do the reading.
You can fix this with two tools that work together. The pandas Styler formats values and adds colors to cells, and st.dataframe renders a Styler directly in a Streamlit app. For number formatting alone, Streamlit’s column_config is often simpler. This guide styles one sales table both ways, tested on pandas 3.0.5 and Streamlit 1.66.1, and explains which styles Streamlit keeps and which it drops.
Key Takeaways
- Pass a pandas Styler to
st.dataframeand Streamlit applies its cell values, text colors, background colors and font weights. - Streamlit does not render some Styler features in
st.dataframe, such as bar charts, hover effects and captions. Usest.tablefor short, static tables that need them. - For number formats only (dollars, percents),
column_configis simpler and keeps the column numeric for sorting. - If both are used,
column_configformatting wins over Styler formatting. - Styler styling is not applied when Streamlit loads rows lazily, which it does by default above 150,000 rows. Set
lazy=Falseif you need it.
What Is the pandas Styler?
The pandas Styler is the object you get from df.style. It holds display rules for a DataFrame (formats, CSS styles, hidden columns) without changing the data. The pandas Table Visualization guide documents every method. Three are enough for most dashboards:
.format()changes how values are displayed, for example97150.0as$97,150..map(func)calls a function on each cell and uses the CSS string it returns. Older pandas versions called this.applymap(), which is gone in pandas 3.0..apply(func, axis=1)calls a function on each row (or column withaxis=0) and returns one CSS string per cell. Use it when a cell’s style depends on other columns.
Step 1: Build the Table
Put the data and the styling in a plain Python module. That keeps the styling testable without starting Streamlit.
# styling.py
import pandas as pd
def build_table() -> pd.DataFrame:
return pd.DataFrame({
"region": ["North", "South", "East", "West"],
"revenue": [182_400.0, 97_150.0, 143_900.0, 61_300.0],
"target": [170_000.0, 120_000.0, 140_000.0, 75_000.0],
"growth": [0.064, -0.021, 0.118, -0.087],
}) Step 2: Style It With pandas
The manager needs three answers at a glance: the formatted amounts, which regions are shrinking, and which missed target. Each answer is one Styler call.
def color_growth(value: float) -> str:
return "color: #b42318" if value < 0 else "color: #067647"
def flag_missed_target(row: pd.Series) -> list[str]:
missed = row["revenue"] < row["target"]
style = "background-color: #fef3f2" if missed else ""
return [style] * len(row)
def style_table(df: pd.DataFrame):
return (
df.style
.format({"revenue": "${:,.0f}", "target": "${:,.0f}", "growth": "{:+.1%}"})
.map(color_growth, subset=["growth"])
.apply(flag_missed_target, axis=1)
.highlight_max(subset=["revenue"], props="font-weight: bold")
) Here is what each line does:
.format()takes a dictionary of column names to format strings."${:,.0f}"adds a dollar sign and thousands separators."{:+.1%}"shows growth as a signed percent..map(color_growth, subset=["growth"])colors negative growth red and positive growth green, only in the growth column..apply(flag_missed_target, axis=1)looks at the whole row, so it can compare revenue with target and shade every cell in that row..highlight_max()is one of several built-in helpers. Others includehighlight_min,highlight_nullandhighlight_between.
We checked the styles pandas computed for each cell. The result for this table:
row 0 revenue $182,400 font-weight: bold
row 0 growth +6.4% color: #067647
row 1 region South background-color: #fef3f2
row 1 revenue $97,150 background-color: #fef3f2
row 1 target $120,000 background-color: #fef3f2
row 1 growth -2.1% color: #b42318; background-color: #fef3f2
row 2 growth +11.8% color: #067647
row 3 region West background-color: #fef3f2
row 3 revenue $61,300 background-color: #fef3f2
row 3 target $75,000 background-color: #fef3f2
row 3 growth -8.7% color: #b42318; background-color: #fef3f2 South and West missed target, so their rows are shaded. Both also have negative growth, shown in red. North has the highest revenue, in bold. Because color_growth and flag_missed_target are plain functions, you can unit test them directly: color_growth(-0.02) returns "color: #b42318".
Step 3: Show the Styler in Streamlit
Pass the Styler to st.dataframe exactly as you would pass a DataFrame. The st.dataframe reference lists pandas.Styler as a supported input.
# app.py
import streamlit as st
from styling import build_table, style_table
st.title("Regional Sales")
df = build_table()
st.subheader("Styled with pandas Styler")
st.dataframe(style_table(df), hide_index=True) Run it with streamlit run app.py. The table keeps Streamlit’s interactive features (column sorting, resizing, search and CSV download) and shows the formats and colors from the Styler. hide_index=True removes the 0 to 3 row numbers, which mean nothing to the reader.
We ran this app with Streamlit’s built-in testing tool, streamlit.testing.v1.AppTest, and it rendered both tables with no exceptions. AppTest is a good way to check a dashboard in CI without opening a browser.
What Streamlit Keeps and What It Drops
The current Streamlit documentation is specific about Styler support in st.dataframe:
| Styler feature | In st.dataframe | Alternative |
|---|---|---|
Formatted values (.format) | Yes | Also possible with column_config |
| Text and background colors | Yes | |
| Font weight | Yes | |
In-cell bars (.bar) | No | ProgressColumn or BarChartColumn in column_config |
| Hover effects, captions | No | st.table for short, static tables |
| Styling when rows load lazily | No | Pass lazy=False |
The lazy loading row matters for large tables. By default, Streamlit loads in-memory pandas DataFrames lazily once they pass 150,000 rows, sending only the visible rows to the browser. Styler styling, search and CSV download are not supported in that mode. For a table that large, consider whether you really need per-cell colors, or aggregate first.
Step 4: Format Numbers With column_config
If all you need is dollar signs and percents, column_config does it without a Styler. The NumberColumn reference lists the built-in formats, including "dollar", "percent", "compact" and printf-style strings.
st.subheader("Formatted with column_config")
st.dataframe(
df,
hide_index=True,
column_config={
"region": st.column_config.TextColumn("Region"),
"revenue": st.column_config.NumberColumn("Revenue", format="dollar"),
"target": st.column_config.NumberColumn("Target", format="dollar"),
"growth": st.column_config.NumberColumn("Growth", format="percent"),
},
) This also renames the headers, which the Styler version left as revenue and growth. Note that "percent" multiplies by 100, so 0.064 shows as 6.40%. Store growth as a fraction, not as 6.4.
You can combine both: a Styler for colors and column_config for labels. If both set a number format for the same column, the column_config format takes precedence.
Which Approach Should You Use?
- Use
column_configwhen you only need formats, labels, widths, progress bars or links. It is less code and works with lazy loading. - Use a Styler when a cell’s color depends on its value or on other columns, as with the missed-target rows above.
- Use
st.tablefor a short, static summary where you want the fuller Styler output, such as captions.
If the table feeds from a file or an API, validate it before styling. A color rule that compares revenue with target will quietly mislead if the target column arrives empty. Our guide to data validation with Pandera shows how to catch that at load time.
Back to Monday Morning
The manager from the opening now sees $97,150 instead of 97150.0, a red -2.1% instead of -0.021, and a shaded row for each region that missed target. She can find South and West in a second, without reading every number. The change was about fifteen lines of pandas and one argument to st.dataframe.
Frequently Asked Questions
Why Does My Styler Bar Chart Not Show in Streamlit?
st.dataframe does not support Styler bars. Use st.column_config.ProgressColumn or BarChartColumn instead, or render a short table with st.table. Hover effects and captions have the same limitation.
Does Styling Change the Data in My DataFrame?
No. The Styler only stores display rules, and the underlying values stay numeric. That is why sorting the revenue column in Streamlit still sorts by number, not by the formatted text.
What Replaced Styler.applymap?
Styler.map. It was added in pandas 2.1 as the new name, and applymap was deprecated and later removed. Code written for older tutorials needs that one rename.
Can I Use a Styler With st.data_editor?
Yes, with a limit. Streamlit applies Styler styles only to non-editable columns in st.data_editor. Editable columns are shown without the Styler styles. Text and number formats from column_config still take precedence, as in st.dataframe.




