2

Is there a way to print some numbers in a dataframe in a different color? So for instance if I wanted to have the 1 in the following table in red. How can I do that?

import pandas as pd
A=pd.DataFrame({'A':[1,2], 'B':[3,4]})

I found libraries like termcolor. But there I can only print normal text in various colors.

C.Schmidt
  • 21
  • 2

1 Answers1

4

In addition to the answer @piRSquared provided which gives great ability for granular control, it appears pandas has added a style feature as of 0.17.1 for addressing this exact issue. Here is a slightly modified version of the example provided in the linked documentation.

enter image description here

mgilbert
  • 3,495
  • 4
  • 22
  • 39
  • @Merlin Yes I generally do that, although since this is rendering in a notebook (to get the html highlighting) it is a bit difficult. I guess I could have copied the code separately but for this short snippet it seemed unecessary – mgilbert Aug 04 '16 at 00:20