Understand the idea
drop_duplicates removes repeated rows. Decide which copy survives; rows that occur only once are always retained.
A small example
For full rows A, B, A, A at indices 0, 1, 2, 3: keeping first retains indices 0, 1; keeping last retains 1, 3.
Follow the code
Apply the idea to the supplied table. Read from top to bottom; the final line displays the result.
df = df.drop_duplicates()
dfWhat each part does
df.drop_duplicates()- remove extra identical rows
keep="first"- retain first occurrence
Other choices for later exercises
subset=["order"]- compare only this key if it must be unique
Your inputs
The editable setup on the right creates df. Run executes the setup and your work from top to bottom.
| order | drink | size | price | tip | date |
|---|---|---|---|---|---|
| 101 | " latte " | LARGE | 6.20 | 1 | 2026-06-01 |
| 102 | TEA | small | 3.10 | 0.5 | 2026-06-02 |
| 103 | " mocha " | LARGE | oops | None | not a date |
| 104 | Latte | Small | None | 0.8 | 2026-06-04 |
| 104 | Latte | Small | None | 0.8 | 2026-06-04 |
| 105 | "tea " | SMALL | 4.20 | 0.6 | 2026-06-05 |
| 106 | ESPRESSO | small | 2.50 | 0.2 | 2026-06-06 |
| 107 | " mocha" | large | 6.80 | 1.5 | 2026-06-07 |
Your task · Follow
- Using df, remove extra exact duplicate rows and preserve the first occurrence and its index.
- Keep the changes in df and display it.
- Use: drop_duplicates().
Hint
These identical rows are confirmed copies; the default keeps the first one.
Reveal solution
One way to do it. Keep any supplied setup in the editor and use this in the Your work section.
df = df.drop_duplicates()
df