What is Pandas DataFrame.isin() in Python?

Overview

The Pandas package in Python lets us manipulate and analyze large data sets in an efficient manner. Pandas DataFrame is a two-dimensional data structure in form of rows and columns.

This DataFrame.isin() method filters each element of the DataFrame to check whether it contains the specified value in a particular column.

Syntax


DataFrame.isin(values)

Parameter

The DataFrame.isin() method takes the following value as an argument:

  • values: This is the Series, Iterable, List, Tuple, Dictionary, or DataFrame to be searched.

Return value

This method returns a DataFrame of Boolean values showing whether each element in DataFrame contain a specified argument value.

Code example

We discuss isin() in detail in the code snippet below. We have two different files in this program: main.py and data.csv.

main.py
data.csv
Name,Designation,Medical Expenses,Bonus,TOTAL
Raj,Chief Technical Officer,1250,13100,14350
Sharad,Accountant,1250,2300,3550
Danish,Senior Web Developer,1250,0,1250
Pawan,Senior Ux/Ui Developer,1250,0,1250
Rijo Paul,Senior Web Developer,1250,2300,3550
Joseph,Senior Web Developer,1250,2300,3550
Aakash,Web Developer,1200,0,1200
Ganesh,Ux/Ui Designer,1200,0,1200
Vinudas,Web Developer,1250,1500,2750
Divya,Web Developer,800,0,800
Joseph,QAA,774,0,774
Sindhu,Web Developer,800,0,800
Deepthi,QAA,749,0,749
Lijin,Accountant,1000,2000,3000

Code explanation

data.csv:

  • This contains employee data: "Name," "Designation," "Medical Expenses," "Bonus," and "TOTAL."

main.py:

  • Line 5: We invoke the pd.read_csv() method to read data.csv in the program as the DataFrame.
  • Line 9: We create a custom search for "Joseph" in the "Name" column of the above-created DataFrame. isin() returns a series of Boolean values in the query variable.
  • Line 11: We pass these Boolean values to the DataFrame to show the query occurrences.

Free Resources