In this article we will learn how to filter rows using Pandas chaining. For this first we have look into some previous terms which are given below :
- Pandas DataFrame : It is a two-dimensional data structure, i.e. the data is tabularly aligned in rows and columns. The Pandas DataFrame has three main components i.e. data, rows and columns.
- Pandas Chaining : Method chaining, in which methods are called on an object sequentially, one after the another. It has always been a programming style that’s been possible with pandas, and over the past few releases, many methods have been introduced that allow even more chaining.
Here we use the concept of chaining in Pandas to filter the dataframe and get the same rows as an output. This can be easily explained with the help of examples. Here we use a dataframe which consists of some data of person as shown below :
Filter by specific value
Here, we select the rows with a specific value in a particular column. The Country column in dataframe is selected with value ‘India’ to filter rows.
Filter by specific grouped values
Here, we select the rows with specific grouped values in a particular column. The Age column in dataframe is selected with value less than 30 to filter rows.
Filter by specific character or string value
Here, we select the rows with specific character or string value in a particular column. The Name column in dataframe is selected with value contains ‘am’ to filter rows.
Filter by values from specific set of values
Here, we select the rows from specific set of values in a particular column. The Country column in dataframe is selected and matched with the given set of values to filter rows.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Spatial Filters - Averaging filter and Median filter in Image Processing
- Python - Filter rows with Elements as Multiple of K
- Python - Filter Rows with Range Elements
- Python - Filter rows with required elements
- Python - Filter immutable rows representing Dictionary Keys from Matrix
- Python Program to Filter Rows with a specific Pair Sum
- Python - Filter rows without Space Strings
- Python - Filter Sorted Rows
- Chaining comparison operators in Python
- NLP | Chunk Tree to Text and Chaining Chunk Transformation
- Implementation of Hashing with Chaining in Python
- Python | Pandas Extracting rows using .loc
- Python | Delete rows/columns from DataFrame using Pandas.drop()
- Python | Extracting rows using Pandas .iloc
- Select first or last N rows in a Dataframe using head() and tail() method in Python-Pandas
- How to skip rows while reading csv file using Pandas?
- Select Rows & Columns by Name or Index in Pandas DataFrame using [ ], loc & iloc
- Concatenate strings from several rows using Pandas groupby
- Python | Pandas dataframe.filter()
- Python | Pandas Series.filter()
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.