🚀 LEVEL UP TO SENIOR:Unlock 500+ Advanced Practical Challenges & Exercises.
🎓 COURSERA PARTNER:Earn professional Google, Meta, and IBM certificates to supercharge your resume.
REFERENCEpandas

pandas Documentation

LOADING ENGINE...

df.iat[]

AI & DATA SCIENCE // df-iat

df.iat[] accesses (or sets) a single scalar value by integer row and column position, the positional counterpart to at[].

Syntax

df.iat[row_position, column_position]

Deep Dive Course

iat[] is to iloc[] exactly what at[] is to loc[]: a scalar-only specialization optimized for the single-value case, but keyed by integer position instead of label. Accessing position (0, 1) with iat[] retrieves the value at the first row and second column by pure position, ignoring whatever labels the index and columns actually carry, the same positional semantics as iloc[] but restricted to a single cell for better performance.

1Understanding df.iat[]

iat[] is to iloc[] exactly what at[] is to loc[]: a scalar-only specialization optimized for the single-value case, but keyed by integer position instead of label. Accessing position (0, 1) with iat[] retrieves the value at the first row and second column by pure position, ignoring whatever labels the index and columns actually carry, the same positional semantics as iloc[] but restricted to a single cell for better performance.

💡

Reach for iat[] over iloc[] specifically when you're getting or setting exactly one scalar value by position — the same performance reasoning that favors at[] over loc[] for the label-based case.

editor.html
import pandas as pd

df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
print(df.iat[1, 1])
localhost:3000

2Practical Example

Here is a real-world application of df.iat[] showing how it is used in production Pandas code.

editor.html
import pandas as pd

df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
df.iat[0, 0] = 99
print(df)
localhost:3000

3Best Practices

Follow these guidelines when working with df.iat[]:

1. Use iat[] instead of iloc[] for single-scalar positional access/assignment when performance matters, such as inside a loop

2. Use iloc[] instead when you might select more than a single value, a whole row, column, or range, by position

3. Use at[] instead of iat[] when accessing by label rather than by integer position

⚠️

Tip: Reach for iat[] over iloc[] specifically when you're getting or setting exactly one scalar value by position — the same performance reasoning that favors at[] over loc[] for the label-based case.

editor.html
import pandas as pd

df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
print(df.iat[1, 1])
localhost:3000

Examples

Example 01Basic Usage
import pandas as pd

df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
print(df.iat[1, 1])
Example 02Advanced Example
import pandas as pd

df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
df.iat[0, 0] = 99
print(df)

Best Practices

  • Use iat[] instead of iloc[] for single-scalar positional access/assignment when performance matters, such as inside a loop
  • Use iloc[] instead when you might select more than a single value, a whole row, column, or range, by position
  • Use at[] instead of iat[] when accessing by label rather than by integer position

Interview Question

When would you choose iat[] over at[], given they both access a single scalar value?

Hint: Think about whether you're identifying the cell by its label or by its position.

The choice comes down entirely to how you're identifying the target cell: at[] takes a row label and a column label, the same label-based identification loc[] uses, while iat[] takes a row position and a column position, the same purely positional identification iloc[] uses. If you know you want the value in the row labeled X, column labeled Y, use at[]; if you know you want the value at row position 3, column position 1, regardless of what labels those happen to carry, use iat[] instead.

Exercises

MediumPractice using df.iat[] in a real scenario.
View Solution
import pandas as pd

df = pd.DataFrame({"a": [1, 2, 3], "b": [4, 5, 6]})
print(df.iat[1, 1])

Frequently Asked Questions

When would you choose iat[] over at[], given they both access a single scalar value?

The choice comes down entirely to how you're identifying the target cell: at[] takes a row label and a column label, the same label-based identification loc[] uses, while iat[] takes a row position and a column position, the same purely positional identification iloc[] uses. If you know you want the value in the row labeled X, column labeled Y, use at[]; if you know you want the value at row position 3, column position 1, regardless of what labels those happen to carry, use iat[] instead.

Related Functions

df-atdf-ilocdf-loc