Series.nlargest(2) is called on the values 9, 9, 9 and 5. What does it return with default arguments?
Correct answer
D. Two of the tied 9 values, ordered by their position in the Series
13 views
D. Two of the tied 9 values, ordered by their position in the Series
13 views
nlargest defaults to keep='first', so it returns exactly n rows and breaks ties by position in the Series; keep='all' returns every tied value and can therefore exceed n rows. Ties are decided on the values themselves, not on the index, so a sorted index does not influence the choice. The same keep argument appears on nsmallest and drop_duplicates.
Asked in: NTS, PPSC IT, Interviews
Not sure why the answer is D? Ask here and get an explanation.