Python Pandas: Does 'loc' and 'iloc' stand for anything?

Question:

I’ve been using pandas for a while now, I understand what loc and iloc do.
But till this day I don’t know if these two things stand for something? Are they short for something or abbreviations? Or are they just random?

I interpret iloc as ‘index-based-location’ which makes sense, but loc is a bit problematic to me, I interpret it as ‘location’ but it doesn’t shout ‘label-based-location’, why couldn’t they call it lloc?

Asked By: Boosted_d16

||

Answers:

TLDR

It doesn’t seem like there is a concrete correlating abbreviation semantically or in the docs; other than it really is just in lamens: "location" vs "integer location". Or Human Readable Labels vs Computer Logical Indexing.

It happens for everyone, especially with new or complicated languages or ideologies; where you know what something does and how to use it, but it’s unsettling when you try to rationalize it’s meaning or sort of explain or talk yourself through it.

Seems that’s a Pythonista’s nightmare and dream all in one.


To properly answer your question, as you are asking "Does loc and iloc stand for anything?" and not What is the difference between loc and iloc?.

I’ve done some research, and found from this github issue
which lead me to this summary. And from these docs, I believe this sums up with these statements

Different Choices for Indexing

Object selection has had a number of user-requested additions in order
to support more explicit location based indexing.

  • .loc: is primarily label based
  • .iloc: is primarily integer position based

And on the chance we want to include ix

  • .ix supports mixed integer and label based access. It is primarily label based, but will fall back to integer positional access continue

Selection By Label

pandas provides a suite of methods in order to have purely label based indexing… – continued

  • The .loc attribute is the primary access method. ↑

Selection By Position

pandas provides a suite of methods in order to get purely integer based indexing…

  • The .iloc attribute is the primary access method. ↑

This does also apply to .at and .iat as well.

Similarly to loc, at provides label based scalar lookups, while, iat provides integer based lookups analogously to iloc

By the way I retracted my close vote and gave you an upvote as that did take some guts to ask for more clarification on an already over asked topic but I do know I as well had issues with that when I was learning too. Hope this helps

Answered By: Jab
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.