+4 votes
in Programming Languages by (9.6k 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 (22.6k points)

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

...