1

There is a dataframe below:

Unnamed:0|Unnamed:1|Unnamed:2 Apple | |50 Orange | |60 Banana | |70 

How can I get the location of value '60' by method df[index, index] without column name?
And the value of '60' is a dynamic result, I only can make sure its location is fixed( at the same row of 'Orange', and next to it with two columns)

1
  • What if all the table is dynamic expect the column of 'Orange', so I only can locate value '60' by using this(at the same row of 'Orange', and next to it with two columns) Commented Sep 25, 2020 at 10:29

2 Answers 2

2

I think you need for selecting second row and third column methods DataFrame.iloc DataFrame.insert or DataFrame.iat, there is used [1,2] because pandas count from 0 - so first Apple should be selected by [0,0]:

df.iloc[1,2] 

Or:

df.iat[1,2] 

For Orange use second row, first column:

df.iloc[1,0] df.iat[1,0] 

EDIT:

If need third column same like Orange position:

df.iloc[(df['fruit'] == 'Orange').to_numpy(), 2] 
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, thank you for answer. What if locating it only by value 'Orange'?
0

maybe something like

import pandas as pd data = {'fruit': ['Apple', 'Orange', 'Banana'], 'price': ['50', '60', '70']} df = pd.DataFrame.from_dict(data) df.loc[df['fruit'] == 'Orange'] 

1 Comment

df.loc[df['fruit'] == 'Orange'].index to get index and df.loc[df['fruit'] == 'Orange'].price to get price.... return array if found multiple values

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.