1

I have some fields that have some junk in them from an upstream process. I'm trying to delete '\r\nName: hwowneremail, dtype: object' from a column that has this junk appended to an email address.

report_df['Owner'].replace('\r\nName: hwowneremail, dtype: object',inplace=True)
report_df['Owner'][26]

Output:

'   [email protected]\r\nName: hwowneremail, dtype: object'

I've also tried the following variants w/o success:

replace('Name: hwowneremail, dtype: object', inplace=True)

replace('\\r\\nName: hwowneremail, dtype: object', inplace=True

replace(r'\r\nName: hwowneremail, dtype: object', inplace=True)

replace('\r\nName: hwowneremail, dtype: object', "", inplace=True)

replace(to_value='\r\nName: hwowneremail, dtype: object', value=' ',inplace=True)

replace('\\r\\nName: hwowneremail, dtype: object',regex=True,inplace=True)

Thanks in advance for your insight!

3 Answers 3

4

As far as I remember, Python Pandas was changed a little bit in replace. You should try passing over a regex keyword argument.

Like so;

report_df['Owner'].replace({'\r\nName: hwowneremail, dtype: object':''},regex=True)
Sign up to request clarification or add additional context in comments.

2 Comments

That did it! Interestingly I started with that, but didn't have regex=True. I added inplace=True and problem solved. Thank You!
This stumped me for a while as well. regex=True is now required, apparently.
0

alternatively you can use:

report_df.Owner.str.replace(r'\r\n.*', '')

Comments

0

Or sometimes just make sure there is no white space before or after the character/str you are looking for(expl. ? ):

df.replace(r'\s*\?\s*', np.nan, regex=True) 

or just make sure you specify you are looking for a string:

df.replace(r'\?', np.nan, regex=True)

and for both cases: and don`t forget

regex=True 

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.