How to find the index of a particular value in a dataframe

+1 vote

Hi. I have a pandas dataframe and I want to find the index of a particular entry in it.

  Name Age
0 Mike 23
1 Eric 25
2 Donna 23
3 Will 23

This is the dataframe. I want to find the index of ‘Donna’. How can I do it?

Apr 8, 2019 in Python by Raj
282,048 views

1 answer to this question.

+2 votes

First, use the dataframe to match the value, and then find the index. Try this:

print(df[df[‘Name’]==’Donna’].index.values)
answered Apr 8, 2019 by Esha
what if i know the index and i want to print the age

Hey,

You can do like this:

dic = {'Name': ["Donna"], 'Age': [23]}
pd.DataFrame(data=dic)
if you know the index and you want to get the age then use

print(df.loc[index, 'age'])
what if we have to compare it with a user input variable

Hi, @Could you please clarify your query about what exactly you want to do?

Yes it worked for me!!!

Related Questions In Python

0 votes
1 answer

How to find the value of a row in a csv file in python and print column and row of that value ?

Hello @Khanhh , Use panda to find the value of ...READ MORE

answered Oct 15, 2020 in Python by Niroj
• 82,840 points
6,834 views
0 votes
1 answer

How to find the index of an item in a list?

One thing that is really helpful in ...READ MORE

answered Dec 3, 2020 in Python by Gitika
• 65,770 points
1,461 views
–1 vote
2 answers

How to find the size of a string in Python?

following way to find length of string  x ...READ MORE

answered Mar 29, 2019 in Python by rajesh
• 1,270 points
2,197 views
0 votes
1 answer

How to find the sum of rows in Pandas dataframe?

You can use a combination groupby function with the sum() method. ...READ MORE

answered May 9, 2019 in Python by Jisha
4,644 views
0 votes
1 answer

How to rename columns in pandas (Python)?

You can use the rename function in ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 8, 2020 by MD 2,115 views
0 votes
1 answer

What is the Difference in Size and Count in pandas (python)?

The major difference is "size" includes NaN values, ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,720 points

edited Jun 8, 2020 by Gitika 2,954 views
0 votes
2 answers

Replacing a row in pandas data.frame

key error. I love python READ MORE

answered Feb 18, 2019 in Data Analytics by anonymous
13,818 views
0 votes
1 answer

Converting a pandas data-frame to a dictionary

Emp_dict=Employee.to_dict('records') You can directly use the 'to_dict()' function ...READ MORE

answered May 23, 2018 in Data Analytics by Bharani
• 4,660 points
4,611 views
0 votes
1 answer

How to find the value of a row in a csv file in python?

If you want to find the value ...READ MORE

answered May 20, 2019 in Python by Sanam
19,280 views
0 votes
1 answer

How to find if a value exists in Pandas dataframe?

Try this:​ for name in df['Name']: ...READ MORE

answered Apr 8, 2019 in Python by Tina
12,674 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP