python code to delete records with two or more empty fields

The key to success is to count NaN cases in each row and check whether it is less than your threshold. You can get it running:

df_exercise.isnull().sum(axis=1) < 2

And to drop rows exceeding this threshold (keep rows within the threshold), run:

df_exercise = df_exercise[df_exercise.isnull().sum(axis=1) < 2]

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top