Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Removing rows with digits and strings in pandas dataframe

I am trying to remove the rows that only have digits or only characters in it. For example, below is the sample pandas dataframe column:

col1:

business
served business
02446681
C96305407PLA
P0116711

In my results, I would need the below values because the first & second rows contain only characters and third row is just digits.

col1:

C96305407PLA
P0116711

Any suggestions would be appreciated !!

like image 762
user3447653 Avatar asked Dec 23 '22 03:12

user3447653


1 Answers

Using two str.contains

df[df.business.str.contains('\d+')&df.business.str.contains('[A-Za-z]')]
Out[48]: 
       business
2  C96305407PLA
3      P0116711
like image 93
BENY Avatar answered Feb 23 '23 05:02

BENY