Filter by specific value
Method 1: Filter rows using eq
Here, we select the rows with a specific value in a particular column. The Country column in Dataframe is selected with the value ‘India’ to filter rows.
Python3
# select the rows with specific value in # a particular column print (data[data.Country.eq( 'India' )]) |
Output:
Method 2: Filter rows using pipe
Here, we select the rows with a specific value in a particular column. The Country column in Dataframe is selected with the value ‘India’ to filter rows using a pipe.
Python3
# Using pipe() method df2 = data.pipe( lambda x: x[ 'Country' ] = = "India" ) print (df2) |
Output:
0 True 1 False 2 True 3 False 4 False 5 True 6 True Name: Country, dtype: bool
How to Filter rows using Pandas Chaining?
In this article, we will learn how to filter rows using Pandas chaining. For this first we have to 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.