user10508414
user10508414

Reputation:

Extract the rows with filtering more than two conditions

Data frame is below

name,id_number
Tom,ABC1234567
Mak,None
Sim,ABC
None,20110159893

Cases

  1. Name should not None

  2. id_number should not None

  3. id_number should not less than 4 numbers

Expected Out

df['out']

Tom,ABC1234567

How to write a function and apply with one condition

Upvotes: 1

Views: 47

Answers (2)

Pyd
Pyd

Reputation: 6159

you need,
df = df.replace('None',np.nan)
df[df.notnull().all(axis=1) & (df['id_number'].str.len() > 3) ]

Upvotes: 0

jezrael
jezrael

Reputation: 862481

Use boolean indexing with Series.notna and Series.str.len and test by Series.gt for greater:

df = df[df['name'].notna() & df['id_number'].notna() & df['id_number'].str.len().gt(4)]
print (df)
  name   id_number
0  Tom  ABC1234567

Alternative:

df = df[df[['name','id_number']].notna().all(axis=1) & df['id_number'].str.len().gt(4)]

Upvotes: 2

Related Questions