Home > Enterprise >  How to highlight the cells containing a specific string in the dataframe using pandas?
How to highlight the cells containing a specific string in the dataframe using pandas?

Time:10-07

Here is the dataframe, what I want is to make the null cells 'grey' background color and 'yellow' background color contains the string 'BLANK'. AND only make actions on COLUMN 'B','C','D','E'.

df1 = pd.DataFrame({'A' : [np.nan, np.nan,np.nan,np.nan, np.nan, np.nan], 
                   'B' : [np.nan, np.nan, np.nan, 'QAHQ052', np.nan,'NO AWD'],
                   'C' : [np.nan, '298561806', np.nan,'(BLANK)', np.nan, np.nan], 
                   'D' : [np.nan, np.nan, '26748',np.nan, np.nan, np.nan], 
                   'E' : ['WER', np.nan, np.nan,'QAC9536, QCD03532, QA39535, (BLANK)', np.nan, 'OGA']})

CodePudding user response:

You can use enter image description here

  • Related