In the given code it displays only the rows without NaN values but i want only the rows with NaN values in a provided column everything has to be removed

df1 = df1[pd.notnull(df1['column_name'])]

1 Answer 1


If I am correct, you are looking to keep only the NaN values. You can use pd.isnull() to check which rows are NaN and then only keep those. Try this:

df1 = df1[pd.isnull(df1['column_name'])]

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.