1. Home
  2. Data Science
  3. Pandas
  4. s.rank(method='dense') is applied to the values [10, 20…

Added 30 Nov -0001

s.rank(method='dense') is applied to the values [10, 20, 20, 30]. What ranks result?

  1. 1, 2, 2, 3, because dense ranking never leaves gaps after ties are collapsed Correct answer
  2. 1, 2, 2, 4, because the next distinct value keeps its positional rank number
  3. 1, 2.5, 2.5, 4, because tied values receive the average of the positions they take
  4. 1, 1, 2, 3, because ties are ordered by their appearance and then renumbered

Correct answer

A. 1, 2, 2, 3, because dense ranking never leaves gaps after ties are collapsed

13 views

MCQSEXAM

Explanation

Dense ranking assigns consecutive ranks to distinct values, so ties share a rank and the next value continues without a gap, giving 1, 2, 2, 3. The default method='average' returns 2.5 for the tied pair, and method='min' still leaves a gap at 4. Choose the method by whether consumers expect ordinal positions or compact levels.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is A? Ask here and get an explanation.

Ask a doubt about this MCQ

Shown after review. No links please.

More Pandas MCQs

Practise all Pandas MCQs

Similar MCQs