Skip to main contentSkip to solution

What will be the output of the loc[] pandas operation?

Solution

✅ Correct Option: 1

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.

Keyboard Shortcuts

  • Left arrow: Previous question
  • Right arrow: Next question
  • S key: Jump to solution
  • Q key: Jump to question