Difference between Pandas .at and .iat Function
- Naveen
- 0
.at
The .at and .iat index accessors are analogous to .loc and .iloc. The difference being that they will return a numpy.ndarray when pulling out a duplicate value, whereas .loc and .iloc return a Series:
.iat
.iat is similar to [] indexing. Because it tries to support both positional and label based indexing, I advise against its’ use in general. It tends to lead to confusing results and violates the notion that “explicit is better than implicit”:
The case where .iat turns out to be useful is given in the pandas documentation:
.iat is exceptionally useful when dealing with mixed positional and label based hierachical indexes.
If you are using pivot tables, or stacking (as described later), .iat can be useful. Note that the pandas documentation continues: However, when an axis is integer based, only label based access and not positional access is supported. Thus, in such cases, it’s usually better to be explicit and use .iloc or .loc.
Popular Posts
Author
-
Naveen Pandey has more than 2 years of experience in data science and machine learning. He is an experienced Machine Learning Engineer with a strong background in data analysis, natural language processing, and machine learning. Holding a Bachelor of Science in Information Technology from Sikkim Manipal University, he excels in leveraging cutting-edge technologies such as Large Language Models (LLMs), TensorFlow, PyTorch, and Hugging Face to develop innovative solutions.
View all posts