Boolean Indexing: How to filter Pandas Data Frame?

Home » News » Boolean Indexing: How to filter Pandas Data Frame?
We can easily filter out any subset of data from the pandas data frame. We can filter values of a column based on conditions from another set of columns? Boolean indexing is very useful here. 


Consider a Load Prediction dataset. We will filter out the data based on some condition using boolean indexing.


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: Filter data using boolean indexing


Suppose we want a list of all females who are not graduate and got a loan. Lets use boolean indexing to filter out the data. You can use the following code:


dataset.loc[(dataset[“Gender”]==”Female”) & (dataset[“Education”]==”Not Graduate”) & (dataset[“Loan_Status”]==”Y”), [“Gender”,”Education”,”Loan_Status”]]


Above code selects the data showing all the females who are not graduate and their loan status is approved. It will only display three columns “Gender”, “Education” and “Loan_Status”. You can display n number of columns based on your requirement. Please try other conditions to filter out the data for the sake of practice.

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