drop_duplicates()

noun

say it: “drop DOO-plih-kits” /ˈdrɑp ˈdupləkɪts/

A pandas method that gives back a table with its repeated rows removed, comparing every column or only the ones you name.

What does drop_duplicates() do in pandas?

drop_duplicates() hands back the table without its repeated rows. subset= names the columns to compare, and keep= says which copy stays: "first" (the default), "last", or False to drop every copy.

intake = intake.drop_duplicates(subset=["animal_id", "intake_date"])
print(len(intake))   # fewer rows: each double entry is gone

In a sentence

  • “drop_duplicates() removed the 12 arrivals that were typed twice.”
  • “With keep="last", drop_duplicates() kept the newest copy of each row.”

Level: Journeyman · More Python terms at this level

Updated