In-built styling options

pandas has predefined formatting rules written and stored as functions that can be readily used.

The highlight_null method highlights all NaNs or Null values in the data with a specified color. In the DataFrame under discussion, the Age and Cabin columns have NaNs. Hence, in the following screenshot, the NaNs are flagged in blue in these columns.

The following snippet highlights the NaN values in these columns:

df.style.highlight_null(null_color = "blue")

This results in the following output:

Figure 9.2: Highlighting Nulls and NANs with blue

The highlight_max and highlight_min methods apply highlighting (with a chosen ...

Get Mastering pandas - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.