0

I have a basic pandas dataframe.

I am trying to conditional highlight just one column.

I have tried to follow the docs: https://pandas.pydata.org/docs/user_guide/style.html

I have got to this point for the dataframe df:

df.style.applymap(lambda x: "background-color: blue" if x>0 else "background-color: green")

I am able to generate a rule for the whole table like this:

enter image description here

But how can i apply the rule to just one column for example the wav column ?

D.L
  • 4,339
  • 5
  • 22
  • 45

1 Answers1

0

With the subset arguement I have now managed to do this:

def format_df(x):
    if x>0:
        return "background-color: blue"
    else:
        return "background-color: green"
    

diffs.style.applymap(lambda x: format_df(x), subset=['wav'])

Which produces this:

enter image description here

Is there a way to calibrate such that there is a heatmap ?

D.L
  • 4,339
  • 5
  • 22
  • 45