1. Home
  2. Data Science
  3. Pandas
  4. df.drop_duplicates(subset=['email'], keep='last') is…

Added 30 Nov -0001

df.drop_duplicates(subset=['email'], keep='last') is applied to a frame with repeated emails. What is retained?

  1. The last row of the frame only, because keep applies to the whole frame rather than rows
  2. Both the first and last occurrences, since keep='last' keeps the boundary rows intact
  3. The last occurrence of each email in the current row order, dropping the earlier ones Correct answer
  4. The first occurrence of each email address, because keep names the copy inspected

Correct answer

C. The last occurrence of each email in the current row order, dropping the earlier ones

15 views

MCQSEXAM

Explanation

drop_duplicates compares the chosen subset of columns and keeps one row per distinct combination, with keep controlling whether the first, last or none survives. keep='last' keeps the final occurrence in the frame's current order, so sorting beforehand decides which record wins. keep=False removes every duplicated row, which is useful for isolating conflicts.

Reference

Asked in: NTS, PPSC IT, Interviews

Preparing for an exam?

Doubts & discussion

Not sure why the answer is C? 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