Controls & Information

Understanding loc and iloc

loc uses labels for indexing (row and column names).

iloc uses integer positions for indexing (0-based indices).

Selection Information

Current Mode:
loc (Label-based)
Selected Cells:
None
Pandas Code:
df
# Click on cells in the grid to generate code # Example for loc: df.loc['B', 'Y'] # Example for iloc: df.iloc[1, 2]

How to Use

1. Select loc or iloc mode

2. Click on row and column headers to select cells

3. View the generated Pandas code

4. Compare the differences between loc and iloc

Interactive DataFrame Grid

Grid Information

This grid represents a DataFrame with:

Row Labels: A, B, C, D, E

Column Labels: W, X, Y, Z, Q

Integer Indices: 0, 1, 2, 3, 4 (for both rows and columns)

DataFrame Visualization - Click on cells to select them

loc vs iloc Comparison

Aspect loc iloc
Indexing Type Label-based Integer position-based
Syntax df.loc[row_label, col_label] df.iloc[row_idx, col_idx]
Inclusive/Exclusive End label is inclusive End index is exclusive
Slicing Example df.loc['A':'C'] → A, B, C df.iloc[0:3] → 0, 1, 2
Use Case When you know row/column labels When you know positions