Remove unwanted parts from strings in a column

前端 未结 9 978
鱼传尺愫
鱼传尺愫 2020-11-22 15:48

I am looking for an efficient way to remove unwanted parts from strings in a DataFrame column.

Data looks like:

    time    result
1    09:00   +52A
         


        
9条回答
  •  天涯浪人
    2020-11-22 16:36

    In the particular case where you know the number of positions that you want to remove from the dataframe column, you can use string indexing inside a lambda function to get rid of that parts:

    Last character:

    data['result'] = data['result'].map(lambda x: str(x)[:-1])
    

    First two characters:

    data['result'] = data['result'].map(lambda x: str(x)[2:])
    

提交回复
热议问题