Formatting
format(formatters)
Apply Python format strings to column values. Use standard Python format mini-language.
formattersdict[str, str]— Mapping of column name → format string
Common format strings:
| Format string | Example input | Example output |
|---|---|---|
"{:.2f}" |
3.14159 |
3.14 |
"{:,.0f}" |
1234567 |
1,234,567 |
"{:.1f}B" |
250.3 |
250.3B |
"{:+.1f}%" |
12.5 |
+12.5% |
"{:06.2f}" |
3.1 |
003.10 |
Example:
df.style().format({
"Revenue": "{:.1f}B",
"Growth": "{:+.1f}%"
}).show()
| Company | Revenue | Profit | Growth | Employees_k |
|---|---|---|---|---|
| Apple | 383.3B | 97.0 | +7.8% | 161 |
| Microsoft | 211.9B | 72.4 | +6.9% | 221 |
| 307.4B | 73.8 | +8.7% | 182 | |
| Amazon | 574.8B | 30.4 | +11.8% | 1541 |
| Meta | 134.9B | 39.1 | +16.4% | 67 |