0

I have a pandas DataFrame with missread string characters in them (like ó for example) and for categorization porpuses I need to clean them up by replacing those characters with the actual letter.

I've tried to use the following code:

df_aux1= df3[df3.MY_COL.str.contains('ó')] 

to isolate it and try to convert it.

Is the replacement on a Dataframe even possible or I'm missing something?

2
  • Your code selects rows which contain the particular character, what code are you using to replace that character? Also you can directly use replace without selecting those rows first. Try this Commented Jan 31, 2019 at 17:41
  • You need to use .loc (python 3+) in order to selects parts of your column. And you are assigning a new dataframe which isn't what you want to do. Posted my answer below! Commented Jan 31, 2019 at 17:53

1 Answer 1

3

Something like this should help you (Python 3+):

df.loc[df['Column Name'] == 'Value you Want to Change', 'Column Name'] = 'New Value'

Essentially what this does it it selects the value you want to change in a specific column in a DataFrameusing .loc and then replaces it in the DataFrame.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.