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,TOTALRaj,Chief Technical Officer,1250,13100,14350Sharad,Accountant,1250,2300,3550Danish,Senior Web Developer,1250,0,1250Pawan,Senior Ux/Ui Developer,1250,0,1250Rijo Paul,Senior Web Developer,1250,2300,3550Joseph,Senior Web Developer,1250,2300,3550Aakash,Web Developer,1200,0,1200Ganesh,Ux/Ui Designer,1200,0,1200Vinudas,Web Developer,1250,1500,2750Divya,Web Developer,800,0,800Joseph,QAA,774,0,774Sindhu,Web Developer,800,0,800Deepthi,QAA,749,0,749Lijin,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 readdata.csvin 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 thequeryvariable. - Line 11: We pass these Boolean values to the DataFrame to show the query occurrences.