How to replace a character in a text in a dataframe

Question:

I have a pandas dataframe X_test that contains one column "review".
I want to check reviews and replace two characters as below:
O ==> 0 and b ==> 6
The replace method replaces just one character.
Any idea, please?

Asked By: SLA

||

Answers:

Try this:

X_test['column_name'] = X_test['column_name'].str.replace('O', '0')
X_test['column_name'] = X_test['column_name'].str.replace('b', '6')
Answered By: Arya Sadeghi
X_test["column"] = X_test["column"].replace({"O": "0", "b": "6"}, regex=True)
Answered By: gustaph
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.