Stripping all trailing empty spaces in a column of a pandas dataframe

前端 未结 2 1425
别那么骄傲
别那么骄傲 2021-02-04 08:26

I have a pandas DF that has many string elements that contains words like this:

\'Frost                              \'
         


        
相关标签:
2条回答
  • 2021-02-04 08:52

    Replace your function with this:

    rawlossDF['damage_description'] = rawlossDF['damage_description'].map(lambda x: x.strip())
    

    You almost had it right, you needed to get rid off the '' inside strip()

    0 讨论(0)
  • 2021-02-04 08:57

    Alternatively you could use str.strip method:

    rawlossDF['damage_description'] = rawlossDF['damage_description'].str.strip()
    
    0 讨论(0)
提交回复
热议问题