How to select rows with multiple filters?

This recipe helps you select rows with multiple filters

Recipe Objective

Have you tried to select a row with many condition?

So this is the recipe on how we can select rows with multiple filters.

Step 1 - Loading Library

We have imported pandas which is needed. import Pandas as pd

Step 2 - Creating a DataFrame

We have created a datafreame by passing a dictionary in pd.DataFrame(). data = {"name": ["A", "B", "C", "D", "E"], "score": [1,2,3,4,5]} df = pd.DataFrame(data) print(df)

Step 3 - Selecting Rows

We want to select rows based on some conditions and we have passed those conditions in the function. Here we want to select rows which has score values greater than 1 and less than 5. df1 = df[(df["score"] > 1) & (df["score"] < 5)] print(df1) So the output comes as

  name  score
0    A      1
1    B      2
2    C      3
3    D      4
4    E      5

  name  score
1    B      2
2    C      3
3    D      4

Download Materials

What Users are saying..

profile image

Abhinav Agarwal

Graduate Student at Northwestern University
linkedin profile url

I come from Northwestern University, which is ranked 9th in the US. Although the high-quality academics at school taught me all the basics I needed, obtaining practical experience was a challenge.... Read More

Relevant Projects

Hands-On Approach to Regression Discontinuity Design Python
In this machine learning project, you will learn to implement Regression Discontinuity Design Example in Python to determine the effect of age on Mortality Rate in Python.

Build an optimal End-to-End MLOps Pipeline and Deploy on GCP
Learn how to build and deploy an end-to-end optimal MLOps Pipeline for Loan Eligibility Prediction Model in Python on GCP

Build a Face Recognition System in Python using FaceNet
In this deep learning project, you will build your own face recognition system in Python using OpenCV and FaceNet by extracting features from an image of a person's face.

Classification Projects on Machine Learning for Beginners - 2
Learn to implement various ensemble techniques to predict license status for a given business.

FEAST Feature Store Example for Scaling Machine Learning
FEAST Feature Store Example- Learn to use FEAST Feature Store to manage, store, and discover features for customer churn prediction machine learning project.

Build a Speech-Text Transcriptor with Nvidia Quartznet Model
In this Deep Learning Project, you will leverage transfer learning from Nvidia QuartzNet pre-trained models to develop a speech-to-text transcriptor.

Build a Customer Churn Prediction Model using Decision Trees
Develop a customer churn prediction model using decision tree machine learning algorithms and data science on streaming service data.

Linear Regression Model Project in Python for Beginners Part 2
Machine Learning Linear Regression Project for Beginners in Python to Build a Multiple Linear Regression Model on Soccer Player Dataset.

Build CI/CD Pipeline for Machine Learning Projects using Jenkins
In this project, you will learn how to create a CI/CD pipeline for a search engine application using Jenkins.

Isolation Forest Model and LOF for Anomaly Detection in Python
Credit Card Fraud Detection Project - Build an Isolation Forest Model and Local Outlier Factor (LOF) in Python to identify fraudulent credit card transactions.