Question:medium

Aditya is working on a DataFrame named df. He has written the statement:

print(df.loc['S2'])

What will the above statement do?

Show Hint

The loc indexer works with labels. A single label passed to df.loc selects one row.
Updated On: Oct 20, 2026
  • Display the data of the row having label 'S2'.
  • Display the columns of the DataFrame.
  • Display the data type of the column having label 'S2'.
  • Display the index numbers of the DataFrame.
Show Solution

The Correct Option is A

Solution and Explanation

Step 1: Break the statement into parts:
The statement has three parts: df, loc and the label 'S2'.
df is the DataFrame, loc means label-based access, and 'S2' is the label we look up.

Step 2: Use the rule for a single label:
With one label inside square brackets, df.loc[label] returns that row.
To get a column, we would write df['name'] or df.loc[:, 'name'] instead.
Since only one label is given and no colon, a row is returned.

Step 3: Match the options with the right command:
Showing columns needs df.columns, so option 2 does not match.
Showing data types needs df.dtypes, so option 3 does not match.
Showing index numbers needs df.index, so option 4 does not match.
Showing the row with label S2 needs df.loc['S2'], so option 1 matches.

Final Answer:
The statement prints the row whose label is 'S2'. This is option 1.
Was this answer helpful?
0