Skip to main contentSkip to solution

Consider a DataFrame 'ResultDF' as follows:

ArnabRamitSamridhiRiyaMallika
Maths9092898194
Science9181917195
Hindi9796886799

Arrange the following commands on the basis of number of values in the output in increasing order:

A. ResultDF.loc['Science']

B. ResultDF.loc[:,'Arnab']

C. ResultDF.loc[['Science', 'Hindi']]

D. ResultDF.loc['Maths'] > 90

Solution

✅ Correct Option: 3

Count the values each command returns.

CommandOutputValues
D. ResultDF.loc['Maths'] > 90Boolean Series; only Ramit (92) and Mallika (94) are True2
B. ResultDF.loc[:,'Arnab']One column, 3 rows3
A. ResultDF.loc['Science']One row, 5 columns5
C. ResultDF.loc[['Science', 'Hindi']]2 rows x 5 columns10

The increasing order is D, B, A, C.


loc[row, col] with : selects all rows, so loc[:,'Arnab'] returns a column. A list of labels such as ['Science', 'Hindi'] returns a DataFrame, not a Series.

Keyboard Shortcuts

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