...

/

Styling Options for DataFrames

Styling Options for DataFrames

Learn about all the different ways to customize the formatting of datasets. Understand how to use the Styler class with Gradio.

Styling the DataFrames

In this lesson, we will explore how we can style the DataFrames to make them more appealing and fit for purpose. This includes formatting the values, highlighting certain cells, adding color, and marking important figures, just to name a few.

The pandas DataFrame has an attribute style that returns a Styler object. Suppose we have a DataFrame defined as df, then we can access this attribute as follows: df.style.

We can then use this accessor to help modify the Styler object and control how the DataFrame is displayed and formatted on the web. This styling is done through CSS. We write style "functions" that take scalars, DataFrame or Series, and it returns like-indexed DataFrame or Series with CSS ‘attribute: value’ pairs for the values. The Styler objects collect these styles before rendering.

We will now explore how we can use the Styler objects to format our DataFrames.

Methods for formatting the display

Styler has many built-in methods to apply formatting to DataFrames. We will go over some commonly used ones.

Format

The format method is used to format the text display value of cells and can be accessed by df.style.format(). It includes the following parameters to tailor how the DataFrame text is formatted:

  • formatter: It is an object that defines how values are displayed.

    • If None, then the ...

Access this course and 1400+ top-rated courses and projects.