Remove unwanted parts from strings in a column

前端 未结 9 891
鱼传尺愫
鱼传尺愫 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:29

    Suppose your DF is having those extra character in between numbers as well.The last entry.

      result   time
    0   +52A  09:00
    1   +62B  10:00
    2   +44a  11:00
    3   +30b  12:00
    4  -110a  13:00
    5   3+b0  14:00
    

    You can try str.replace to remove characters not only from start and end but also from in between.

    DF['result'] = DF['result'].str.replace('\+|a|b|\-|A|B', '')
    

    Output:

      result   time
    0     52  09:00
    1     62  10:00
    2     44  11:00
    3     30  12:00
    4    110  13:00
    5     30  14:00
    

提交回复
热议问题