Data Selection with LOC and ILOC in Pandas

Extract the bottom-right three-by-three subset of the DataFrame using both LOC and ILOC.

Practice selecting precise data subsets using Python's LOC and ILOC indexing methods. Gain hands-on experience extracting specific rows and columns from data frames.

Key Insights

  • Practice using Python's LOC and ILOC indexing methods by extracting the last three rows and columns from a data frame.
  • The targeted data subset includes columns named fuel efficiency, latest launch, and power performance factor.
  • Complete this indexing task twice—once utilizing LOC and once employing ILOC—to master the differences between these selection techniques.

Note: These materials offer prospective students a preview of how our classes are structured. Students enrolled in this course will receive access to the full set of materials, including video lectures, project-based assignments, and instructor feedback.

For this next part, I'd like you to get a little practice with LOC and ILOC. So our task is to get the last three rows and last three columns. As it says here, the little three by three at the bottom right of this data frame.

If we look up here, we're in the last three rows here. We want those three rows, but specifically at these last three columns. So this little three by three right here is what we're intending to get.

And it should ultimately look something like this. Because the data frame, it'll have its column names and its row numbers. And then it will have these sets of values for each one.

Fuel efficiency, latest launch, and power performance factor. So your task is do this twice. Once using ILOC, and then once using LOC.

Get a little practice. All right, I'll see you in the next video. We'll go over the solution.

Data Analytics Certificate: Live & Hands-on, In NYC or Online, 0% Financing, 1-on-1 Mentoring, Free Retake, Job Prep. Named a Top Bootcamp by Forbes, Fortune, & Time Out. Noble Desktop. Learn More.

But first, give it a try yourself.

Colin Jaffe

Colin Jaffe is a programmer, writer, and teacher with a passion for creative code, customizable computing environments, and simple puns. He loves teaching code, from the fundamentals of algorithmic thinking to the business logic and user flow of application building—he particularly enjoys teaching JavaScript, Python, API design, and front-end frameworks.

Colin has taught code to a diverse group of students since learning to code himself, including young men of color at All-Star Code, elementary school kids at The Coding Space, and marginalized groups at Pursuit. He also works as an instructor for Noble Desktop, where he teaches classes in the Full-Stack Web Development Certificate and the Data Science & AI Certificate.

Colin lives in Brooklyn with his wife, two kids, and many intricate board games.

More articles by Colin Jaffe

How to Learn Machine Learning

Master machine learning with hands-on training. Use Python to make, modify, and test your own machine learning models.

Yelp Facebook LinkedIn YouTube Twitter Instagram