Difference between pandas.iloc and .iat?

I recently noticed that the function where I repeat the lines DataFrameusing .ilocis very slow. I found out that there is a faster method called .iatthat is considered equivalent .iloc. I tried, and it reduced the runtime by about 75%.

But I'm a bit hesitant: why is there an "equivalent" method that is faster? There must be some difference between the inner workings of the two and the reason why they both exist, and not just faster. I tried searching everywhere, but even the pandas documentation says that

DataFrame.iat
Fast integer scalar location.

Like iloc, iat provides an integer search. You can also set these indexes.

And it doesn’t help.

Are there any restrictions on use .iat? Why faster; is it sloppier? Or am I just switching to .iatand happily forget an .ilocever existing one?

+7
source share
2 answers

iatand atwork only with a scalar, so it’s very fast. Slower, more general functions - ilocand loc.

You can check the documents :

[] ( , , ..), , , . , - at iat, .

loc, at , iat iloc.

+11

iat at , iloc loc .
:
iloc[1:2,5:8] , iat[1:2,5:8]

+2

Source: https://habr.com/ru/post/1686422/


All Articles