Search⌘ K
AI Features

Indexing by Name

Explore techniques for indexing pandas DataFrames by name using the loc accessor. Understand differences between loc and iloc with integer and string indexes, slicing rules, and how to handle categorical indexes. Learn how to extract rows and columns effectively based on index names, with caution on data types and sorting requirements.

We'll cover the following...

Let’s explore indexing by the name of index entries in a DataFrame. This is done by indexing on loc. If you’re confused between loc and iloc, just remember that iloc indexes on position and that computer programs generally use the variable i to represent an index position.

One thing to be aware of is the difference between iloc and loc when dealing with integer indexes. In particular, slicing has different behavior. Slicing with iloc follows the half-open interval (includes the first index but not the last). Slicing with loc follows the closed ...