Python Pandas replace() not working

后端 未结 3 1276
甜味超标
甜味超标 2020-12-04 04:23

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 th

相关标签:
3条回答
  • 2020-12-04 04:38

    alternatively you can use:

    report_df.Owner.str.replace(r'\r\n.*', '')
    
    0 讨论(0)
  • 2020-12-04 04:46

    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)
    
    0 讨论(0)
  • 2020-12-04 04:48

    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 
    
    0 讨论(0)
提交回复
热议问题