Extract all numeric characters from a pandas series (all groups)

前端 未结 3 1390
时光取名叫无心
时光取名叫无心 2020-12-21 19:58

I am trying to use the str.extract(\'(\\d+)\') method on a pandas series to get the digits of a phone number that looks like: (123) 456-7890

Using this method only r

3条回答
  •  攒了一身酷
    2020-12-21 20:29

    df = pd.DataFrame({'no': ['(123) 456-7890', '+321 / 555-7890']})
    df['clean'] = df.no.str.extractall('(\d+)').unstack().apply(''.join, axis=1)
    

    Result:

        no              clean
    0   (123) 456-7890  1234567890
    1   +321 / 555-7890 3215557890
    

提交回复
热议问题