1
+ """
2
+ 2882. Drop Duplicate Rows
3
+ Solved
4
+ Easy
5
+ Companies
6
+ Hint
7
+ DataFrame customers
8
+ +-------------+--------+
9
+ | Column Name | Type |
10
+ +-------------+--------+
11
+ | customer_id | int |
12
+ | name | object |
13
+ | email | object |
14
+ +-------------+--------+
15
+ There are some duplicate rows in the DataFrame based on the email column.
16
+
17
+ Write a solution to remove these duplicate rows and keep only the first occurrence.
18
+
19
+ The result format is in the following example.
20
+
21
+
22
+
23
+ Example 1:
24
+ Input:
25
+ +-------------+---------+---------------------+
26
+ | customer_id | name | email |
27
+ +-------------+---------+---------------------+
28
+ | 1 | Ella | emily@example.com |
29
+ | 2 | David | michael@example.com |
30
+ | 3 | Zachary | sarah@example.com |
31
+ | 4 | Alice | john@example.com |
32
+ | 5 | Finn | john@example.com |
33
+ | 6 | Violet | alice@example.com |
34
+ +-------------+---------+---------------------+
35
+ Output:
36
+ +-------------+---------+---------------------+
37
+ | customer_id | name | email |
38
+ +-------------+---------+---------------------+
39
+ | 1 | Ella | emily@example.com |
40
+ | 2 | David | michael@example.com |
41
+ | 3 | Zachary | sarah@example.com |
42
+ | 4 | Alice | john@example.com |
43
+ | 6 | Violet | alice@example.com |
44
+ +-------------+---------+---------------------+
45
+ Explanation:
46
+ Alic (customer_id = 4) and Finn (customer_id = 5) both use john@example.com, so only the first occurrence of this email is retained."
47
+ """
48
+
49
+ import pandas as pd
50
+
51
+ def dropDuplicateEmails (customers : pd .DataFrame ) -> pd .DataFrame :
52
+ return customers .drop_duplicates ("email" )
0 commit comments