The objective is to highlight a cell if it contain * or **.
I have the impression this can be achieved as below
import numpy as np
import pandas as pd
df = pd.DataFrame ( {'Data': ['foo', '*', 'bar'],
'myda': ['**', '*', 'wer']} )
def highlight_ (s, props=''):
return np.where ( s.str.contains ( "*" ), props, '' )
df.apply ( highlight_, props='background-color:yellow', axis=1 )
However, the compiler return an re.error.
re.error: nothing to repeat at position 0
May I know how to properly implement this?


s.str.contains ("\*"). You have to escape the asterisk.df.style.apply(...instead of justdf.apply(...