Recently began branching out from my safe place (R) into Python and and am a bit confused by the cell localization/selection in Pandas. I've read the documentation but I'm struggling to understand the practical implications of the various localization/selection options.
Is there a reason why I should ever use .loc or .iloc over at, and iat or vice versa? In what situations should I use which method?
Note: future readers be aware that this question is old and was written before pandas v0.20 when there used to exist a function called
.ix. This method was later split into two -locandiloc- to make the explicit distinction between positional and label based indexing. Please beware thatixwas discontinued due to inconsistent behavior and being hard to grok, and no longer exists in current versions of pandas (>= 1.0).
loc: only work on index
iloc: work on position
at: get scalar values. It's a very fast loc
iat: Get scalar values. It's a very fast iloc
Also,
atandiatare meant to access a scalar, that is, a single element in the dataframe, whilelocandilocare ments to access several elements at the same time, potentially to perform vectorized operations.
http://pyciencia.blogspot.com/2015/05/obtener-y-filtrar-datos-de-un-dataframe.html