1

I want to know the value of the cell that intersects between a column value and another column, for ex :

>>> a = pd.DataFrame({'A': ['A1', 'A2', 'A3'], 'A1':[1, 3, 4], 'A2':[3, 6, 8], 'A3':[4,7,9]})
>>> a
    A  A1  A2  A3
0  A1   1   3   4
1  A2   3   6   7
2  A3   4   8   9

In this I am going to take two inputs from the user, one for column A row value and another to search for in the other column headers, for ex :

input1 = 'A1'
input2 = 'A2'

I want to get the intersection of A1 in rows and A2 in column so the output should be '3'. I can see a simple solution to be to get the index of the row first, then the index of column and then the get the value using iloc but i am looking for a more efficient way.

techdoodle
  • 85
  • 6

1 Answers1

2

Use .loc method

a.loc[a['A'] == input1, input2]
YOLO
  • 20,181
  • 5
  • 20
  • 40