EasyNo. 2882
Drop Duplicate Rows — LeetCode 2882 Python Solution
- Topics
- Pandas
- Reading time
- 2 min
- Source
- leetcode.com
Table schema
DataFrame customers +-------------+--------+ | Column Name | Type | +-------------+--------+ | customer_id | int | | name | object | | email | object | +-------------+--------+ There are some duplicate rows in the DataFrame based on the email column. Write a solution to remove these duplicate rows and keep only the first occurrence.Example
DataFrame customers
+-------------+--------+
| Column Name | Type |
+-------------+--------+
| customer_id | int |
| name | object |
| email | object |
+-------------+--------+Python solution
import pandas as pd
def dropDuplicateEmails(customers: pd.DataFrame) -> pd.DataFrame:
return customers.drop_duplicates(subset=['email'])Complexity
- Time
- O(n)
- Space · auxiliary
- O(1) to O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 2877 | Create a DataFrame from List | Easy |
| 2874 | Maximum Value of an Ordered Triplet II | Medium |
| 2873 | Maximum Value of an Ordered Triplet I | Easy |
| 0057 | Insert Interval | Medium |
| 0192 | Word Frequency | Medium |
| 0193 | Valid Phone Numbers | Easy |
Frequently asked questions
- How hard is LeetCode 2882. Drop Duplicate Rows?
LeetCode 2882. Drop Duplicate Rows is rated Easy on LeetCode.
- What topics does LeetCode 2882. Drop Duplicate Rows cover?
LeetCode 2882. Drop Duplicate Rows is tagged Pandas on LeetCode.