Remove unwanted parts from strings in a column

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

    There's a bug here: currently cannot pass arguments to str.lstrip and str.rstrip:

    http://github.com/pydata/pandas/issues/2411

    EDIT: 2012-12-07 this works now on the dev branch:

    In [8]: df['result'].str.lstrip('+-').str.rstrip('aAbBcC')
    Out[8]: 
    1     52
    2     62
    3     44
    4     30
    5    110
    Name: result
    

提交回复
热议问题