+5 votes
in Programming Languages by (40.5k points)
I want to find the element at row/column (x,y) in a dataframe. If I use df[x,y], it gives KeyError. Which function should I use to access the value at (x,y)?

1 Answer

+3 votes
by (77.2k points)
selected by
 
Best answer

You can use "iat" to get a single value at a given row/column in a Pandas DataFrame or Series.

Example:

>>> import pandas as pd

>>> df = pd.DataFrame([[0, 2, 3], [0, 4, 1], [10, 20, 30]], columns=['A', 'B', 'C'])

>>> df

    A   B   C

0   0   2   3

1   0   4   1

2  10  20  30

>>> df.iat[1,2]

1

>>> df.iat[2,2]

30


...