Tsallaka zuwa abun ciki
Justice Tech School

Find Duplicates

duplicated marks repeated rows. drop_duplicates removes them and keeps the first by default.

Example
import pandas as pd
import numpy as np
d = pd.DataFrame({'k': [1, 1, 2, 2], 'v': ['a', 'a', 'b', 'c']})
print(d.duplicated().tolist())
print(d.drop_duplicates())
print(d.drop_duplicates(subset='k', keep='last'))

Result

[False, True, False, False]
   k  v
0  1  a
2  2  b
3  2  c
   k  v
1  1  a
3  2  c

Exercise

Remove duplicates.

d.()

Quiz Test

Which row is kept by default?

These free lessons are for learning. Join a full course for projects, mentor feedback and a verified certificate.