Replacing part of string in python pandas dataframe

后端 未结 2 1409
隐瞒了意图╮
隐瞒了意图╮ 2020-12-14 07:27

I have a similar problem to the one posted here:

Pandas DataFrame: remove unwanted parts from strings in a column

I need to remove newline characters from w

相关标签:
2条回答
  • 2020-12-14 07:51

    You could use regex parameter of replace method to achieve that:

    misc['product_desc'] = misc['product_desc'].replace(to_replace='\n', value='', regex=True)
    
    0 讨论(0)
  • 2020-12-14 07:52

    strip only removes the specified characters at the beginning and end of the string. If you want to remove all \n, you need to use replace.

    misc['product_desc'] = misc['product_desc'].str.replace('\n', '')
    
    0 讨论(0)
提交回复
热议问题