1

I have a df with values in a column.
df :

        a    
0    abc_test_0120_12346
1    def_abc def_0420_9658

I want to take out only int/numbers.
Excepted Output is df :

        a    
0    012012346
1    04209658
2
  • I have tried this df.a.str.extract('(^\d*)') Commented Apr 13, 2020 at 6:03
  • "What about "abc_123 def_456"? Is the answer "123456" or "123 456" with the space? Commented Apr 13, 2020 at 6:04

1 Answer 1

4

Idea is replace non numbers to emty strings:

df['a'] = df.a.str.replace('\D+', '')
print (df)
           a
0  012012346
1   04209658
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.