What does the loc method allow you to do? (Select 1) - more information please

I’m currently completing the Data Analysis with Python cert, and I just completed the 3rd lesson, and wanted more information about the test question challenge for this video:

Here is the test question:

What does the loc method allow you to do? (Select 1)

  • A. Retrieve a subset of rows and columns by supplying integer-location arguments.
  • B. Access a group of rows and columns by supplying label(s) arguments.
  • C. Returns the first n rows based on the integer argument supplied.

I knew that loc() is used for filtering after watching the first three videos in this series, and knew that the answer was either A or B before attempting to answer. What I was wondering is what is the difference between integer-location arguments and label(s) arguments. I don’t recall either of those things being mentioned before during the first three videos, and did a quick google search on label(s) arguments but came up empty so far. Is label(s) arguments a commonly used term, or is that just how they are referred to in this video? Any information on the different types of arguments and the proper terms would be appreciated.

Thanks in advance!

a quick google search but came up empty so far

I feel like I did a google search for “python loc method” and the first entry had enough for me (someone that doesn’t know Python) to get the correct answer.

I would highly recommend getting good at looking up things like this. That is one of the most important skills a developer has.

1 Like

To put it bluntly: an integer is a number, a label is a string.
The appropriate methods therefore are .iloc() for integers (like “integer-location”) and .loc() for labels.
In Dataframes .loc() does kind of the same as just plain bracket notation df[“label”]. I’d need to google myself to remind myself of the differences though - I usually use brackets, but .loc() is more versatile somehow ^^°
Anyway, “label” refers to the name of a column and because .loc() a function/method, the supplied info is an argument. No idea if there is a “common used term” because that’s just not an everyday way of speaking, unless you want to specificaly point out the difference.

1 Like

in the content so far there was no mention of iloc() method which takes integers, just the loc method, which led to me asking about the phrases “label(s)” and “integer-location” arguments. I never asked about what loc() does, and stated specifically in my post I understand what the method does.

I went ahead and undid the solution as I checked it earlier because my question:

Is label(s) arguments a commonly used term, or is that just how they are referred to in this video?

still hasn’t technically been answered, but you answer led me to the information that was missing which caused the initial confusion about arguments. So thanks.

I don’t think you’ll get an answer on that, because “commonly used term” is hard to determine in a context that in itself isn’t common.
Personally I’d think it’s just how it’s called in the video. I cannot say for sure, because I have no idea how I would even check that though.

In terms of “types of arguments” it’s usually just specified in the documentation or description of a function on what data-type and/or format can be given as arguments. I’d say I never came across a term like “label argument” but as I must have watched the video in the past, I might just not have paid attention to wording. Though generally it’s more like “you provide a string/label as argument here and an integer there and that’s an object…” or similar.

ok, I will go ahead and make that the solution then, thank you.

Seems like this might already be answered, but on the off chance it’s useful, I found this page of the Pandas user guide helpful in explaining the argument differences between loc and iloc. It does briefly describe loc as “primarily label based”. In particular, contrasting the “Selection by label” and “Selection by position” sections was helpful to me.

Just my personal experience, loc started becoming meaningful in selecting data when I began working with frames using a multi-index and non-integer based indices. Like when datetime periods are used as the index for time-series data where slicing by label (date or time) is more useful than slicing by their position in the dataset. I find myself using iloc more when working with non-monotomic indexes, particularly when I don’t want to reindex a dataset that already has a useful one established (like random, unique IDs from the database they came from).

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.