Remove unwanted parts from strings in a column

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

    A very simple method would be to use the extract method to select all the digits. Simply supply it the regular expression '\d+' which extracts any number of digits.

    df['result'] = df.result.str.extract(r'(\d+)', expand=True).astype(int)
    df
    
        time  result
    1  09:00      52
    2  10:00      62
    3  11:00      44
    4  12:00      30
    5  13:00     110
    

提交回复
热议问题