Python Forum

Full Version: Find only the rows containing null values
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
In a given dataset, I want to print the rows which have null value but with their actual values and not any bool values.
For example, if the dataset is given like this,
dict = {'First Score':[100, 90, 80, 95], 
        'Second Score': [np.nan, 45, 56, np.nan], 
        'Third Score':[10, 40, 80, 98]} 
df = pd.DataFrame(dict)
df.isnull()
Here, it gives the output in bool.
But, I want an output where, if I am missing any value in that particular row, I want the output to be like this.
Second Score NAN 45 56 NAN
import pandas as pd 
import numpy as np 
dict = {'First Score':[100, 90, 80, 95], 
        'Second Score': [np.nan, 45, 56, np.nan], 
        'Third Score':[10, 40, 80, 98]}

df = pd.DataFrame(dict)
print(df)
print(df[df.isnull().any(axis=1)])
Output:
First Score Second Score Third Score 0 100 NaN 10 1 90 45.0 40 2 80 56.0 80 3 95 NaN 98 First Score Second Score Third Score 0 100 NaN 10 3 95 NaN 98
Thank you for helping me.