.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:
Syntax
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[]
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
- Trying to select several cells
- Mixing labels and positions
- 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: