I have tried many times, but seems the \'replace\' can NOT work well after use \'loc\'. For example I want to replace the \'conlumn_b\' with an regex for the row that the \'
I think you need filter in both sides:
m = df['conlumn_a'] == 'apple' df.loc[m,'conlumn_b'] = df.loc[m,'conlumn_b'].astype(str).replace(r'^(11+)','XXX',regex=True) print (df) conlumn_a conlumn_b 0 apple 123 1 banana 11 2 apple XXX 3 orange 33