How to find missing values in each row and column using Apply function in Pandas library?

Home » News » How to find missing values in each row and column using Apply function in Pandas library?
apply function returns some value after passing each row/column of a data frame with some function. The function can be default or user-defined or lambda. We will create a user defined function which calculates missing values and returns the count. First we will call this function for all columns and then for all rows using apply function.


Consider a Load Prediction dataset. We will try to find out count of missing values in each row and column using apply function.

Step 1: Import the required libraries

import pandas as pd
import numpy as np

Step 2: Load the dataset

dataset = pd.read_csv(“C:/train_loan_prediction.csv”)


Step 3: Create a function which returns count of missing values


def num_missing(x):
  return sum(x.isnull())
  
Step 4: Find out number of missing values in each column
  
print(“Missing values per column:”)
print(dataset.apply(num_missing, axis=0)) 


axis=0 defines that function is to be applied on each column.


Step 5: Find out number of missing values in each row


print(“Missing values per row:”)
print(dataset.apply(num_missing, axis=1).head()) 


axis=1 defines that function is to be applied on each row.


You can also use lambda function with apply. Here is an example.

Leave a Reply

Your email address will not be published. Required fields are marked *

New Providers
Binolla

The Broker
More then 2 million businesses
See Top 10 Broker

gamehag

Online game
More then 2 million businesses
See Top 10 Free Online Games

New Games
Lies of P

$59.99 Standard Edition
28% Save Discounts
See Top 10 Provider Games

COCOON

$24.99 Standard Edition
28% Save Discounts
See Top 10 Provider Games

New Offers
Commission up to $1850 for active user of affiliate program By Exness

Top Points © Copyright 2023 | By Topoin.com Media LLC.
Topoin.info is a site for reviewing the best and most trusted products, bonus, offers, business service providers and companies of all time.

Discover more from Top Points

Subscribe now to keep reading and get access to the full archive.

Continue reading