What will be the output of the loc[] pandas operation?
What will be the output of the loc[] pandas operation?
Solution
Among the given options, Option 1 is the only one that describes indexing, which is what loc[] does: it selects rows and columns from a DataFrame and returns the selected data.
Strictly, loc[] selects by label, while integer-position selection is done by iloc[]. Option 1 is the closest match because the other three describe different operations.
Option 2: removing rows or columns is done by drop().
Option 3: combining DataFrames along an axis is done by concat().
Option 4: changing row or column labels is done by rename().
loc[] = label-based, iloc[] = integer position-based.
Related questions:
2026: 24 May Shift 1
2026: 23 May Shift 1
2025: 16 May Shift 1
2025: 14 May Shift 1