How to find location of multiple elements in the DataFrame

There are several ways to find the location of multiple elements in a DataFrame. Below are three common approaches.

Using isin()

The code snippet creates a list of target students you want to find. It then uses the isin() method on the 0th column to select rows. Finally, it retrieves the index of those rows using the .index attribute.

Python3




import pandas as pd
index_list = students[students.isin(['Ankit', 'Swapnil','Delhi'])]
print(index_list)


Output:

         0   1      2    3
0 Ankit NaN Delhi NaN
1 Swapnil NaN Delhi NaN
2 NaN NaN NaN NaN
3 NaN NaN Delhi NaN
4 NaN NaN NaN NaN

Find location of an element in Pandas dataframe in Python

In this article, we will see how to find the position of an element in the dataframe using a user-defined function. Let’s first Create a simple dataframe with a dictionary of lists.

Similar Reads

How to find an element in Pandas Dataframe?

In a Pandas DataFrame, you can find the position of a specific element or check for its existence using various methods. Here are a few common ways. Let’s create a dataframe first and see each method one by one....

How to find location of multiple elements in the DataFrame

...

Frequently Asked Questions (FAQs)

...

Contact Us