2

I have to delete row if in the same line i have id1 and id2 are empty. I did these lines but got error.

d = {'id1': ['Y22', 'X23', None], 'id2': ['Y10', "Y14", None], 'id3':[77,22,13]}
df = pd.DataFrame(data=d)

df = df[df[pd.notnull(df['id1'])and df[pd.notnull(df['id2'])]]
1
  • df[~(df['id1'].isna() & df['id2'].isna())] Commented Jun 4, 2019 at 12:14

1 Answer 1

6

Use df.all() on axis=1 and check if all values in id1 and id2 are not null, then use it as boolean mask:

df[~df[['id1','id2']].isna().all(axis=1)]

   id1  id2  id3
0  Y22  Y10   77
1  X23  Y14   22
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you but it not what i want i want to delete just when the two values in the same row are NULL.
@Miss so if both the ids are None dont select the row? Can you test again?

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.