Home > Mobile >  How to replace a character in a text in a dataframe
How to replace a character in a text in a dataframe

Time:01-17

I have a pandas dataframe X_test that contains an index and one column. the column contains a comment text (book reviews). I want to check the text and replace characters as : O ==> 0, b ==> 6 The pandas.dataframe.replace take all the text and check it for replacement so it doesn't meet my need. Any idea, please? thank you

CodePudding user response:

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')

CodePudding user response:

X_test["column"] = X_test["column"].replace({"O": "0", "b": "6"}, regex=True)
  • Related