Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

pandas

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?

like image 906
Boosted_d16 Avatar asked Feb 16 '19 00:02

Boosted_d16


People also ask

What is the difference between Pandas loc and ILOC?

When it comes to selecting rows and columns of a pandas DataFrame, loc and iloc are two commonly used functions. Here is the subtle difference between the two functions: loc selects rows and columns with specific labels. iloc selects rows and columns at specific integer positions.

What does DataFrame loc stand for?

loc is label-based, which means that we have to specify the name of the rows and columns that we need to filter out. For example, let's say we search for the rows whose index is 1, 2 or 100. We will not get the first, second or the hundredth row here.

What is the use of ILOC and loc?

loc and iloc is slicing of dataframe in Pandas. Function . loc is primarily used for label indexing and . iloc function is mainly applied for integer indexing.


1 Answers

TLDR

It doesn't seem like there is a concrete correlating abreviation symantically or in the docs; other than it really is just lamens "location" vs "integer location". Human Readable Labels vs Computer Logical Indexing. It happens for everyone, especially with new or complicated languages or ideoligies; 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...

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

like image 108
Jab Avatar answered Oct 18 '22 02:10

Jab