s.rank(method='dense') is applied to the values [10, 20, 20, 30]. What ranks result?
A
1, 2, 2, 3, because dense ranking never leaves gaps after ties are collapsed
Correct answer
B
1, 2, 2, 4, because the next distinct value keeps its positional rank number
C
1, 2.5, 2.5, 4, because tied values receive the average of the positions they take
D
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
⚔️
Challenge a friend on Pandas
Same MCQs, timed, live leaderboard. Send the link on WhatsApp – no sign-up needed.
Create challenge
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
Doubts & discussionNot sure why the answer is A? Ask here and get an explanation.
Ask a doubt about this MCQ
‹ Previous MCQ A categorical column with 20 categories is grouped, but only 3 categories occur in the data. Why does observed=True shrink the result? Next MCQ › df.resample('M').sum() is called on a DataFrame whose date lives in an ordinary string column rather than the index. What happens?