daily pastebin goal
81%
SHARE
TWEET

Untitled

a guest Nov 17th, 2017 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data =  pd.DataFrame(np.random.randn(5, 3), columns=list('ABC'))
  2. #print (data)
  3.  
  4. def highlight_cols(x):
  5.     #copy df to new - original data are not changed
  6.     df = x.copy()
  7.     #select all values to default value - red color
  8.     df.loc[:,:] = 'background-color: red'
  9.     #overwrite values grey color
  10.     df[['B','C']] = 'background-color: grey'
  11.     #return color df
  12.     return df    
  13.  
  14. data.style.apply(highlight_cols, axis=None)
RAW Paste Data
Top