Apply a CSS-styling function elementwise.
Updates the HTML representation with the result.
func
should take a scalar and return a string.
A valid 2d input to DataFrame.loc[<subset>], or, in the case of a 1d input or single key, to DataFrame.loc[:, <subset>] where the columns are prioritised, to limit data
to before applying the function.
Pass along to func
.
Notes
The elements of the output of func
should be CSS styles as strings, in the format âattribute: value; attribute2: value2; â¦â or, if nothing is to be applied to that element, an empty string or None
.
Examples
>>> def color_negative(v, color): ... return f"color: {color};" if v < 0 else None >>> df = pd.DataFrame(np.random.randn(5, 2), columns=["A", "B"]) >>> df.style.map(color_negative, color='red')
Using subset
to restrict application to a single column or multiple columns
>>> df.style.map(color_negative, color='red', subset="A") ... >>> df.style.map(color_negative, color='red', subset=["A", "B"]) ...
Using a 2d input to subset
to select rows in addition to columns
>>> df.style.map(color_negative, color='red', ... subset=([0,1,2], slice(None))) >>> df.style.map(color_negative, color='red', subset=(slice(0,5,2), "A")) ...
See Table Visualization user guide for more details.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4