I am trying to highlight the single whole cell in pandas based on text. For example, if Recommend is 'SELL', I want to highlight in red and green for 'BUY'. Appreciate if someone can guide me on this.
def color_negative_red(value):
if value < 0:
color = 'red'
elif value > 0:
color = 'green'
else:
color = 'black'
return 'color: %s' % color
import pandas as pd
data = {'Stock': ['TSLA','GM','GOOG','MMM'],
'Diff': [-200,-50,150,50],
'Recommend' : ['SELL','SELL','BUY','BUY']
}
df = pd.DataFrame(data, columns = ['Stock', 'Diff', 'Recommend'])
df.style.applymap(color_negative_red, subset=['Diff'])
### how to get a conditional highlight based on 'Recommend' ?????


