Python Pandas replace()无法正常工作 [英] Python Pandas replace() not working
本文介绍了Python Pandas replace()无法正常工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一些字段在上游过程中有一些垃圾.我正在尝试从已将此垃圾附加到电子邮件地址的列中删除'\ r \ nName:hwowneremail,dtype:object'.
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]
输出:
' Jane.Doe@company.com\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)
提前感谢您的见解!
推荐答案
据我所知,Python Pandas在replace中做了一些改动.您应该尝试传递正则表达式关键字参数.
As far as I remember, Python Pandas was changed a little bit in replace. You should try passing over a regex keyword argument.
像这样;
report_df['Owner'].replace({'\r\nName: hwowneremail, dtype: object':''},regex=True)
这篇关于Python Pandas replace()无法正常工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文