Я бы определил отдельную функцию, отражающую ваши условия, и applymap
:
def colorize(x):
try:
lower = x.lower()
# condition 1, pass the corresponding list
if lower in ['us','ca']: return 'background-color: red'
# condition 2
for s in ['apple', 'sam']:
if s in lower: return 'background-color: yellow'
# condition 3
for s in ['xxx','bbb', 'aaa']:
if s in lower: return 'background-color: blue'
return ''
except:
return ''
# toy data
df = pd.DataFrame({'Country':['USA','us','usa','ca', 'CA'],
'V1':["Apple", "Applex", 'APPLE', 'SAMSUNG','xxx'],
'V2':['Samsung', 'Semsung', 'SamSung1', 'apple', 'bbbb'],
'V3':['SAMSUNG', 'SS','APPLEXX', 'APPLEs', 'aaa']
})
df.style.applymap(colorize)
Вывод: