How to Color Polars DataFrame

Continue working with the Polars library while being able to color and style the table

AI image generated by ChatGPT. Prompt: A polar bear painting in a snowy landscape.

Since the Polars library was released in 2022, it has rapidly gained popularity due to being an ultra-speed DataFrame library. Compared with Pandas, the white bear was tested and proved to be way faster. According to the official Polars website, it is claimed to reach more than 30x performance gains.

However, nothing is perfect. The Polars library seems to have some limits.

When it comes to styling tables, Polars offers fewer options while Pandas has a built-in styler available. If you want to color a Polars DataFrame, a straightforward solution is converting the table into Pandas.

But wait… what if some code needed to be run later?

Examples show Polars table before and after styling in this article. Image by author.

This means we have to run Pandas which can result in a drastically slower speed. Another choice is converting the table back to Polars after styling. Then, if we want to style the result, the same process has to be repeated. Even though these solutions work, they are quite inconvenient.