Python Forum
Find only the rows containing null values
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find only the rows containing null values
#1
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
Reply
#2
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
If you can't explain it to a six year old, you don't understand it yourself, Albert Einstein
How to Ask Questions The Smart Way: link and another link
Create MCV example
Debug small programs

Reply
#3
Thank you for helping me.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  find the sum of a series of values that equal a number ancorte 1 491 Oct-30-2023, 05:41 AM
Last Post: Gribouillis
  Any tips to how to find out values? nevlindan 1 717 Apr-27-2023, 09:14 PM
Last Post: deanhystad
  How to express null value klatlap 3 854 Mar-25-2023, 10:40 AM
Last Post: klatlap
Photo How to select NULL and blank values from MySQL table into csv python300 9 2,409 Dec-27-2022, 09:43 PM
Last Post: deanhystad
  Write Null values as 0.0 (float) type in csv mg24 3 1,364 Dec-07-2022, 09:04 PM
Last Post: deanhystad
  Loop through values in dictrionary and find the same as in previous row Paqqno 5 1,901 Mar-27-2022, 07:58 PM
Last Post: deanhystad
  value null when update in json file 3lnyn0 6 3,214 Dec-30-2021, 05:52 PM
Last Post: ndc85430
  The code I have written removes the desired number of rows, but wrong rows Jdesi1983 0 1,625 Dec-08-2021, 04:42 AM
Last Post: Jdesi1983
  Calculate next rows based on previous values of array divon 0 1,760 Nov-23-2021, 04:44 AM
Last Post: divon
Question Find all values in drop down menu with bs4 DonaldBug13 1 4,016 Aug-06-2021, 06:16 PM
Last Post: Axel_Erfurt

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020