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

GCP MLOps Project to Deploy ARIMA Model using uWSGI Flask
Build an end-to-end MLOps Pipeline to deploy a Time Series ARIMA Model on GCP using uWSGI and Flask

Ensemble Machine Learning Project - All State Insurance Claims Severity Prediction
In this ensemble machine learning project, we will predict what kind of claims an insurance company will get. This is implemented in python using ensemble machine learning algorithms.

Learn to Build a Siamese Neural Network for Image Similarity
In this Deep Learning Project, you will learn how to build a siamese neural network with Keras and Tensorflow for Image Similarity.

House Price Prediction Project using Machine Learning in Python
Use the Zillow Zestimate Dataset to build a machine learning model for house price prediction.

Build a Multi-Class Classification Model in Python on Saturn Cloud
In this machine learning classification project, you will build a multi-class classification model in Python on Saturn Cloud to predict the license status of a business.

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.

NLP Project to Build a Resume Parser in Python using Spacy
Use the popular Spacy NLP python library for OCR and text classification to build a Resume Parser in Python.

OpenCV Project to Master Advanced Computer Vision Concepts
In this OpenCV project, you will learn to implement advanced computer vision concepts and algorithms in OpenCV library using Python.

Deploy Transformer BART Model for Text summarization on GCP
Learn to Deploy a Machine Learning Model for the Abstractive Text Summarization on Google Cloud Platform (GCP)

Demand prediction of driver availability using multistep time series analysis
In this supervised learning machine learning project, you will predict the availability of a driver in a specific area by using multi step time series analysis.