Selecting Rows with loc & iloc
Pandas provides two main indexers for selecting rows: loc (label-based) and iloc (position-based).
iloc: Position-Based Selection
Use iloc with integer positions (like list indexing):
Loading Pandas Playground...
loc: Label-Based Selection
Use loc with index labels:
Loading Pandas Playground...
Selecting Rows and Columns Together
Both loc and iloc can select rows AND columns:
Loading Pandas Playground...
Negative Indexing with iloc
Access from the end using negative indices:
Loading Pandas Playground...
Selecting Single Values
Use .at and .iat for scalar access:
Loading Pandas Playground...
Exercise: Row Selection
Loading Exercise...
Exercise: loc Selection
Loading Exercise...
Key Points
ilocuses integer positions (0, 1, 2, ...)locuses index labels- Both support
[rows, columns]syntax - Slicing with
locincludes the end label - Slicing with
ilocexcludes the end position - Use
.at/.iatfor fast single-value access

