40

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?

Boosted_d16
  • 13,340
  • 35
  • 98
  • 158
  • 5
    It's Label based locating, and Integer based locating see [here](https://stackoverflow.com/questions/31593201/pandas-iloc-vs-ix-vs-loc-explanation-how-are-they-different) it's been asked before. I'd say pronounce it **Label of Column** and **Index/Integer of Column** – Jab Feb 16 '19 at 00:56
  • 3
    Two separate things, I want to understand the meaning behind the words, not the functionality of it. – Boosted_d16 Feb 16 '19 at 01:10
  • Would [this](http://jose-coto.com/slicing-methods-pandas) help? In particular the last section where it says: *"So, this is what you need to remember:"* – Jab Feb 16 '19 at 01:17
  • Also see [this](https://github.com/datacarpentry/python-ecology-lesson/issues/7) issue on github, It seems it isn't really a standard abbreviation persay but more "location" as lamens location, `loc`, and "integer location" as the way a computer sees it. `iloc` – Jab Feb 16 '19 at 01:22
  • You're not getting it, I understand what they do, but I wanted to know if they stand for something? Loc does't really translate to LABEL based indexing does it? So I wanted to understand what they've named it Loc and iLoc – Boosted_d16 Feb 16 '19 at 01:22
  • Ah see now you are answering the question. Loc = Location, and iLoc = Integer Location. Which is what I normally think of but Location could be index or label to me. Which is why I wanted to understand if there's more to it. – Boosted_d16 Feb 16 '19 at 01:24
  • 1
    I guess loc is location and iloc is integer location. The assumption being that location stands for what the actual indexes are. It used to trip me up because index and integer both start with "i".... I wonder if there is anything else to the nomenclature too. – Frâncio Rodrigues Feb 16 '19 at 01:27
  • 1
    I knew as you said *"I've been using pandas for a while now, I understand what loc and iloc do"* Just doesn't seem like there is a real correlating abreviation symantically. It really is just *lamens* location vs integer location. Human readable labels vs computer logical indexing. Happens for everyone where you know what something does but it's unsettling when you try to rationalize it's meaning or how it does it. Seems that's a Pythonista's nightmare and dream all in one – Jab Feb 16 '19 at 01:28
  • This isn't the 80's. public api, without question, should not be shortened or be an acronym. Imagine, reducing all the time spent trying to figure out what this function and its ilk stand for. we'd probably be 50% bionic by now – fontno Nov 24 '21 at 04:38

1 Answers1

34

TLDR

It seems there is no 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 programmer's nightmare and dream all in one.


How I see it, put yourself in a situation where you work at a department store and someone asks you where to find the soda, you can either tell them it's in the "soda" aisle or it's on isle 19. (or: aisles["soda"] vs aisles[19]) both point to the same location.


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 on this as well, 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

Jab
  • 26,853
  • 21
  • 75
  • 114
  • 3
    Only the last part (under "To sum up") is relevant, the rest talks about what loc/iloc do again. You might want to consider removing those parts to make your answer clearer. – Boosted_d16 Feb 16 '19 at 19:12
  • 1
    I edited it a bit for readability; I know I could have answered with just my comment but I wanted to include as much context as I felt necessary for newcomers unless it really isn’t helpful. – Jab Feb 16 '19 at 23:53
  • 2
    I like this. "location" vs "integer location". Human Readable Labels vs Computer Logical Indexing. – chia yongkang May 22 '20 at 04:50