Preliminaries

import pandas as pd
import numpy as np

Create Pandas dataframe with random numbers

df = pd.DataFrame(np.random.randint(1000,100000,size=(15, 4)), columns=list('ABCD'))
df.head()
A B C D
0 23709 64741 23686 91188
1 65680 82624 75561 98275
2 92203 37811 76966 38658
3 84619 17500 5890 79898
4 68736 50615 11204 32913

For demonstration purposes, let's create a pivot table

pivot = pd.pivot_table(df, index = ['A', 'B'],
                       values = ['C', 'D'], aggfunc = ['sum', 'mean'])
pivot
sum mean
C D C D
A B
6405 89881 86138 82878 86138 82878
13323 26813 29352 41448 29352 41448
20598 98959 85063 68091 85063 68091
23709 64741 23686 91188 23686 91188
39780 17193 49436 81402 49436 81402
47835 40995 74271 65407 74271 65407
53481 82855 19225 26853 19225 26853
65680 82624 75561 98275 75561 98275
68736 50615 11204 32913 11204 32913
84619 17500 5890 79898 5890 79898
87051 17441 99532 68376 99532 68376
88006 3533 25610 46405 25610 46405
88274 98894 78792 44986 78792 44986
89596 44772 45295 21454 45295 21454
92203 37811 76966 38658 76966 38658

Highlight the maximum and minimum values

pivot.style.highlight_max(color='green').highlight_min(color='red')
sum mean
C D C D
A B
6405 89881 86138 82878 86138 82878
13323 26813 29352 41448 29352 41448
20598 98959 85063 68091 85063 68091
23709 64741 23686 91188 23686 91188
39780 17193 49436 81402 49436 81402
47835 40995 74271 65407 74271 65407
53481 82855 19225 26853 19225 26853
65680 82624 75561 98275 75561 98275
68736 50615 11204 32913 11204 32913
84619 17500 5890 79898 5890 79898
87051 17441 99532 68376 99532 68376
88006 3533 25610 46405 25610 46405
88274 98894 78792 44986 78792 44986
89596 44772 45295 21454 45295 21454
92203 37811 76966 38658 76966 38658

Add color scales to Pandas DataFrame

pivot.style.background_gradient(cmap='viridis')
sum mean
C D C D
A B
6405 89881 86138 82878 86138 82878
13323 26813 29352 41448 29352 41448
20598 98959 85063 68091 85063 68091
23709 64741 23686 91188 23686 91188
39780 17193 49436 81402 49436 81402
47835 40995 74271 65407 74271 65407
53481 82855 19225 26853 19225 26853
65680 82624 75561 98275 75561 98275
68736 50615 11204 32913 11204 32913
84619 17500 5890 79898 5890 79898
87051 17441 99532 68376 99532 68376
88006 3533 25610 46405 25610 46405
88274 98894 78792 44986 78792 44986
89596 44772 45295 21454 45295 21454
92203 37811 76966 38658 76966 38658

Add table captions

pivot.style.set_caption('Random dataframe with colormaps, with a caption.')\
      .background_gradient(cmap='viridis')
Random dataframe with colormaps, with a caption.
sum mean
C D C D
A B
6405 89881 86138 82878 86138 82878
13323 26813 29352 41448 29352 41448
20598 98959 85063 68091 85063 68091
23709 64741 23686 91188 23686 91188
39780 17193 49436 81402 49436 81402
47835 40995 74271 65407 74271 65407
53481 82855 19225 26853 19225 26853
65680 82624 75561 98275 75561 98275
68736 50615 11204 32913 11204 32913
84619 17500 5890 79898 5890 79898
87051 17441 99532 68376 99532 68376
88006 3533 25610 46405 25610 46405
88274 98894 78792 44986 78792 44986
89596 44772 45295 21454 45295 21454
92203 37811 76966 38658 76966 38658

Add color bars to Pandas DataFrame

pivot.style.bar(color='Green')
sum mean
C D C D
A B
6405 89881 86138 82878 86138 82878
13323 26813 29352 41448 29352 41448
20598 98959 85063 68091 85063 68091
23709 64741 23686 91188 23686 91188
39780 17193 49436 81402 49436 81402
47835 40995 74271 65407 74271 65407
53481 82855 19225 26853 19225 26853
65680 82624 75561 98275 75561 98275
68736 50615 11204 32913 11204 32913
84619 17500 5890 79898 5890 79898
87051 17441 99532 68376 99532 68376
88006 3533 25610 46405 25610 46405
88274 98894 78792 44986 78792 44986
89596 44772 45295 21454 45295 21454
92203 37811 76966 38658 76966 38658
pd.__version__, np.__version__
('1.1.0', '1.19.1')