2 years ago

#74718

test-img

geen21

Replace multiple string containing a string with Pandas

This work for the string "AAA" :

df['B'] = df.A.str.replace(r'(^.*AAA.*$)', 'ZZZ',  regex=True)

How can I do if I want to replace multiple string by 'ZZZ'?

df['B'] = df.A.str.replace(r'(^.*AAA.*$)' or r'(^.*BBB.*$)', 'ZZZ',  regex=True)

I tried this but it does not work

python

pandas

data-science

0 Answers

Your Answer

Accepted video resources