Q:

How to select rows with one or more nulls from a Pandas DataFrame without listing columns explicitly?

belongs to collection: Python Pandas Programs

0

Rows in pandas are the different cell (column) values that are aligned horizontally and also provide uniformity. Each row can have the same or different value. Rows are generally marked with the index number but in pandas we can also assign index names according to the needs. In pandas, we can create, read, update and delete a column or row value.

For this purpose, we will use pandas.isnull() method. This method is used to traverse along the entire DataFrame and returns another DataFrame with Boolean values. It returns True if there is some NaN value and False if not.

To work with pandas, we need to import pandas package first, below is the syntax:

import pandas as pd

All Answers

need an explanation for this answer? contact us directly to get an explanation for this answer

Let us understand with the help of an example:

# Importing pandas package
import pandas as pd

# To create NaN values, you must import numpy package, 
# then you will use numpy.NaN to create NaN values
import numpy as np

# Create an empty list
result = []

# Creating a dictionary with some NaN values
d={
    "Name":['Hari','Mohan','Neeti','Shaily'],
    "Age":[25,np.NaN,np.NaN,21],
    "Gender":['Male','Male',np.NaN,'Female'],
    "Profession":['Doctor','Teacher','Singer',np.NaN]
}

# Now we will create DataFrame
df = pd.DataFrame(d)

# Viewing the original DataFrame
print("Original DataFrame:\n")
print(df,"\n\n")

# Using pd.isnull(df)
print(pd.isnull(df))

Output:

Example: Select rows with one or more nulls from a Pandas DataFrame

need an explanation for this answer? contact us directly to get an explanation for this answer

total answers (1)

Python Pandas Programs

This question belongs to these collections

Similar questions


need a help?


find thousands of online teachers now
How to convert column value to string in pandas Da... >>
<< How to take column slices of DataFrame in pandas?...