Skip to content
Advertisement

Styling Large Pandas Dataframe

I have seen similar posts but have not found an answer that works. I am trying to style a very large Pandas dataframe.

I have a function like the following. All it does is assign a red background to negative values and a green background to positive values.

JavaScript

I style the entire dataframe:

JavaScript

And finally output to HTML:

JavaScript

The problem is the green styling only applies to the first 150 rows or so. This is because there are so many cells that are green there are too many selectors.

  1. I am aware this is an issue with the browser, not with Pandas.
  2. I am aware splitting the DF is a possibility, but in this case it is impractical.
  3. I am aware exporting to Excel works, but I need the output as HTML.

Instead of selectors, how can I apply a class or something to all the values that need to be green?

I think this part of the documentation has the answer. I just do not know how to apply that code to my situation. I have been at this for a while, and help is appreciated. Thanks!

StackOverflow post with possible answer

Advertisement

Answer

All of the links you cite tell you exactly how to do it. The pandas own documentation even gives you a direct example of what to do. The example below refactors pandas own documentation.

JavaScript
JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement