Tutorial
This tutorial builds a styled table step by step, adding one feature at a time. We use the Big Tech financials dataset throughout.
import polars as pl
import polarise
df = pl.DataFrame({
"Company": ["Apple", "Microsoft", "Google", "Amazon", "Meta"],
"Revenue": [383.3, 211.9, 307.4, 574.8, 134.9],
"Profit": [ 97.0, 72.4, 73.8, 30.4, 39.1],
"Growth": [ 7.8, 6.9, 8.7, 11.8, 16.4],
"Employees_k": [ 161, 221, 182, 1541, 67],
})
Step 1 — Render the raw table
Just calling .style() renders a plain table:
df.style().show()
| Company | Revenue | Profit | Growth | Employees_k |
|---|---|---|---|---|
| Apple | 383.3 | 97.0 | 7.8 | 161 |
| Microsoft | 211.9 | 72.4 | 6.9 | 221 |
| 307.4 | 73.8 | 8.7 | 182 | |
| Amazon | 574.8 | 30.4 | 11.8 | 1541 |
| Meta | 134.9 | 39.1 | 16.4 | 67 |
Step 2 — Add a gradient
Apply a sequential colormap to the Revenue column:
(df.style()
.gradient("Revenue", cmap="CET_L19")
.show()
)
| Company | Revenue | Profit | Growth | Employees_k |
|---|---|---|---|---|
| Apple | 383.3 | 97.0 | 7.8 | 161 |
| Microsoft | 211.9 | 72.4 | 6.9 | 221 |
| 307.4 | 73.8 | 8.7 | 182 | |
| Amazon | 574.8 | 30.4 | 11.8 | 1541 |
| Meta | 134.9 | 39.1 | 16.4 | 67 |
Step 3 — Highlight the best profit
Chain a highlight_max on top of the gradient:
(df.style()
.gradient("Revenue", cmap="CET_L19")
.highlight_max("Profit", fill="gold")
.show()
)
| Company | Revenue | Profit | Growth | Employees_k |
|---|---|---|---|---|
| Apple | 383.3 | 97.0 | 7.8 | 161 |
| Microsoft | 211.9 | 72.4 | 6.9 | 221 |
| 307.4 | 73.8 | 8.7 | 182 | |
| Amazon | 574.8 | 30.4 | 11.8 | 1541 |
| Meta | 134.9 | 39.1 | 16.4 | 67 |
Step 4 — Apply a fashion preset
Replace the default style with fashion_minimal for a cleaner look:
(df.style()
.gradient("Revenue", cmap="CET_L19")
.highlight_max("Profit", fill="gold")
.fashion_minimal()
.show()
)
| Company | Revenue | Profit | Growth | Employees_k |
|---|---|---|---|---|
| Apple | 383.3 | 97.0 | 7.8 | 161 |
| Microsoft | 211.9 | 72.4 | 6.9 | 221 |
| 307.4 | 73.8 | 8.7 | 182 | |
| Amazon | 574.8 | 30.4 | 11.8 | 1541 |
| Meta | 134.9 | 39.1 | 16.4 | 67 |
Step 5 — Add a title and footnote
(df.style()
.gradient("Revenue", cmap="CET_L19")
.highlight_max("Profit", fill="gold")
.fashion_minimal()
.title("Big Tech Financials", subtitle="FY 2023 — Revenue in $B")
.footnote("Source: Company annual reports.")
.show()
)
Big Tech Financials
FY 2023 — Revenue in $B
| Company | Revenue | Profit | Growth | Employees_k |
|---|---|---|---|---|
| Apple | 383.3 | 97.0 | 7.8 | 161 |
| Microsoft | 211.9 | 72.4 | 6.9 | 221 |
| 307.4 | 73.8 | 8.7 | 182 | |
| Amazon | 574.8 | 30.4 | 11.8 | 1541 |
| Meta | 134.9 | 39.1 | 16.4 | 67 |
Source: Company annual reports.
Step 6 — Format the numbers
Apply format strings to clean up the display:
(df.style()
.gradient("Revenue", cmap="CET_L19")
.highlight_max("Profit", fill="gold")
.fashion_minimal()
.title("Big Tech Financials", subtitle="FY 2023 — Revenue in $B")
.footnote("Source: Company annual reports.")
.format({"Revenue": "{:.0f}B", "Growth": "{:+.1f}%"})
.show()
)
Big Tech Financials
FY 2023 — Revenue in $B
| Company | Revenue | Profit | Growth | Employees_k |
|---|---|---|---|---|
| Apple | 383B | 97.0 | +7.8% | 161 |
| Microsoft | 212B | 72.4 | +6.9% | 221 |
| 307B | 73.8 | +8.7% | 182 | |
| Amazon | 575B | 30.4 | +11.8% | 1541 |
| Meta | 135B | 39.1 | +16.4% | 67 |
Source: Company annual reports.
What's next?
- Browse the API Reference for all available methods
- See Examples for more complete use cases
- Check Colors & Colormaps for the full list of available
cmapvalues