0

I am trying to apply a Bar Style to all of the data in the dataframe, except the last row, which is supposed to be the Total row.

import pandas as pd
import numpy as np
data =  pd.DataFrame(np.random.randn(5, 2), columns=list('AB'))
data.loc['Total'] = data.sum()

           A                B
0      -1.224620    -0.373898
1       0.75568      0.997875
2      -1.284663    -0.211903
3      -0.274813    -0.871816
4       1.256267    -0.742521
Total  -0.772143    -1.202263
soky
  • 5
  • 4

1 Answers1

2

It was explained in the docs, that

A tuple is treated as (row_indexer, column_indexer)

You just need to twist a bit the subset option.

On your data

import pandas as pd
import numpy as np
data =  pd.DataFrame(np.random.randn(5, 2), columns=list('AB'))
data.loc['Total'] = data.sum()

data.style.bar(subset = ([0,1,2,3,4], ['A', 'B']))

it gives

enter image description here