From the course: Data Analysis with Python and Pandas

Unlock this course with a free trial

Join today to access over 24,900 courses taught by industry experts.

The .loc accessor

The .loc accessor

- [Instructor] Now that we've taken a look at the iloc method, it's time to look at loc. The loc method allows us to access data via its labels. I tend to find that I use this method a lot more than iloc, because a lot of the time I'm trying to access both rows as well as a subset of columns and referencing column names via other labels. So as opposed to referencing column index 012, I probably want to be accessing columns price, columns customer ID, column sales amount, that type of thing. So having this label based accessor makes it really nice. Additionally, if we do have a custom index, the loc method's going to be often more intuitive if we want to grab specific values with those custom indexes. So let's take a look. So once again, we're specifying DF here for data frame. This is just to let you know that this works on both data frames and series. We first pass in our row labels, so we could access a single row label. So for example, if our index had the word pizza in it, we…

Contents