Difference between Pandas .at and .iat Function


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 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

Spread the knowledge

Leave a Reply

Your email address will not be published. Required fields are marked *