← Back to Pandas Course | Chapter 4: Indexing & Selection | Lesson 4 of 7

.at[] and .iat[]

at and iat read or write exactly one cell, and they are faster than loc and iloc for that job.

In this page:

  1. .at[] and .iat[]
Syntax
python
df.at[row_label, column_label]
df.iat[row_position, column_position]

.at[] and .iat[]

at uses labels: df.at[row_label, col_label]. iat uses positions: df.iat[row_pos, col_pos]. They only handle a single scalar, which makes them quicker than the general indexers.

Note: Use at and iat inside loops that update single cells.

Example: .at[] and .iat[]

python
import pandas as pd

df = pd.DataFrame({"score": [70, 85]}, index=["ann", "bob"])
print(df.at["bob", "score"])
print(df.iat[0, 0])
df.at["ann", "score"] = 99
print(df)

# Output:
# 85
# 70
#      score
# ann     99
# bob     85
Related Topics
Common Mistakes
  1. Trying to select several cells
  2. Mixing labels and positions
  3. Using them when a vectorized update would do
Chapter Summary
  • at is a label-based scalar accessor
  • iat is position-based
  • Both target one cell
  • Faster than loc and iloc
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.