Accessing subsets of data in Pandas is achieved primarily through two explicit indexing accessors:
loc: Label-based indexing (select by column names and row index labels).iloc: Integer position-based indexing (select by integer offset: 0, 1, 2, ...).loc uses names/labels, iloc uses integer positions..loc[row_label, col_label].loc (INCLUSIVE of endpoints!)[0:3], the stop endpoint 3 is excluded. But with loc, both the start label and the stop label are INCLUDED!.iloc[row_idx, col_idx].iloc operates strictly on 0-based integer positions, adhering to standard Python slice rules (stop position is EXCLUDED):
| Feature | df.loc[] | df.iloc[] |
|---|---|---|
| Lookup Mode | By Label / Name | By Integer Position |
| Row Selection | df.loc['R101'] | df.iloc[0] |
| Slice Endpoints | Inclusive ('A':'C' includes C) | Exclusive (0:3 stops at 2) |
| Boolean Masking | Supported (df.loc[df['Score'] > 90]) | Not directly supported |
.iloc stand for?.loc and .iloc?['A', 'B', 'C'] and column 'Revenue', how do you access the Revenue of row 'B' using label-based indexing?'Score' into .iloc?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Reading JSON, SQL Databases & Parquet Files | Boolean Indexing & DataFrame Querying |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Combine 15 complete courses, 150 chapters, 541 topics, live SQL/Power BI/Tableau dashboards, and Scikit-Learn capstones at MSK Institute Shikohabad or Live Online.