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 .iloc accessor

The .iloc accessor

- [Instructor] Alright, so in the last lesson I mentioned that I was going to introduce a couple methods that were preferred over traditional Python indexing. One of those is the iloc method, which is the preferred way to access values via their positional index. This method works even when series have a custom non integer index. So even when I pass an integer values on a series that has a text-based index, we'll still be looking positionally, which allows me to easily grab, let's say, the first five rows by slicing to a stop point of five. I don't need to worry about that index label. It's also a little bit more efficient than traditional Python slicing, and it's recommended by Pandas creators for data access. So here we have df. This could either be a series or a data frame to access values from, I'm showing data frame here because this iloc method applies to both series and data frames. When we're talking about a single series, all we have are rows, but when we start working with a…

Contents