mirror of
				https://gitee.com/coder-xiaomo/leetcode-problemset
				synced 2025-11-04 11:43:12 +08:00 
			
		
		
		
	
		
			
				
	
	
		
			45 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
			
		
		
	
	
			45 lines
		
	
	
		
			1.6 KiB
		
	
	
	
		
			HTML
		
	
	
	
	
	
<pre>
 | 
						|
DataFrame customers
 | 
						|
+-------------+--------+
 | 
						|
| Column Name | Type   |
 | 
						|
+-------------+--------+
 | 
						|
| customer_id | int    |
 | 
						|
| name        | object |
 | 
						|
| email       | object |
 | 
						|
+-------------+--------+
 | 
						|
</pre>
 | 
						|
 | 
						|
<p>There are some duplicate rows in the DataFrame based on the <code>email</code> column.</p>
 | 
						|
 | 
						|
<p>Write a solution to remove these duplicate rows and keep only the <strong>first</strong> occurrence.</p>
 | 
						|
 | 
						|
<p>The result format is in the following example.</p>
 | 
						|
 | 
						|
<p> </p>
 | 
						|
<pre>
 | 
						|
<strong class="example">Example 1:</strong>
 | 
						|
<strong>Input:</strong>
 | 
						|
+-------------+---------+---------------------+
 | 
						|
| customer_id | name    | email               |
 | 
						|
+-------------+---------+---------------------+
 | 
						|
| 1           | Ella    | emily@example.com   |
 | 
						|
| 2           | David   | michael@example.com |
 | 
						|
| 3           | Zachary | sarah@example.com   |
 | 
						|
| 4           | Alice   | john@example.com    |
 | 
						|
| 5           | Finn    | john@example.com    |
 | 
						|
| 6           | Violet  | alice@example.com   |
 | 
						|
+-------------+---------+---------------------+
 | 
						|
<strong>Output: </strong> 
 | 
						|
+-------------+---------+---------------------+
 | 
						|
| customer_id | name    | email               |
 | 
						|
+-------------+---------+---------------------+
 | 
						|
| 1           | Ella    | emily@example.com   |
 | 
						|
| 2           | David   | michael@example.com |
 | 
						|
| 3           | Zachary | sarah@example.com   |
 | 
						|
| 4           | Alice   | john@example.com    |
 | 
						|
| 6           | Violet  | alice@example.com   |
 | 
						|
+-------------+---------+---------------------+
 | 
						|
<strong>Explanation:</strong>
 | 
						|
Alic (customer_id = 4) and Finn (customer_id = 5) both use john@example.com, so only the first occurrence of this email is retained.
 | 
						|
</pre>
 |