|
|
@@ -0,0 +1,52 @@
|
|
|
+# 2882. Drop Duplicate Rows
|
|
|
+
|
|
|
+import sys
|
|
|
+
|
|
|
+import pandas as pd
|
|
|
+
|
|
|
+def dropDuplicateEmails(customers: pd.DataFrame) -> pd.DataFrame:
|
|
|
+ return customers.drop_duplicates(subset=['email'], keep='first')
|
|
|
+
|
|
|
+
|
|
|
+def main() -> int:
|
|
|
+
|
|
|
+ def r(customers: pd.DataFrame, exp: pd.DataFrame) -> None:
|
|
|
+ res: pd.DataFrame = dropDuplicateEmails(customers)
|
|
|
+ print(f"dropDuplicateEmails({customers}) = {res} | exp: {exp}")
|
|
|
+ pass
|
|
|
+
|
|
|
+ r(
|
|
|
+ pd.DataFrame.from_dict(
|
|
|
+ {
|
|
|
+ "customer_id": [1, 2, 3, 4, 5, 6],
|
|
|
+ "name": ["Ella", "David", "Zachary", "Alice", "Finn", "Violet"],
|
|
|
+ "email": [
|
|
|
+ "emily@example.com",
|
|
|
+ "michael@example.com",
|
|
|
+ "sarah@example.com",
|
|
|
+ "john@example.com",
|
|
|
+ "john@example.com",
|
|
|
+ "alice@example.com",
|
|
|
+ ],
|
|
|
+ }
|
|
|
+ ),
|
|
|
+ pd.DataFrame.from_dict(
|
|
|
+ {
|
|
|
+ "customer_id": [1, 2, 3, 4, 6],
|
|
|
+ "name": ["Ella", "David", "Zachary", "Alice", "Violet"],
|
|
|
+ "email": [
|
|
|
+ "emily@example.com",
|
|
|
+ "michael@example.com",
|
|
|
+ "sarah@example.com",
|
|
|
+ "john@example.com",
|
|
|
+ "alice@example.com",
|
|
|
+ ],
|
|
|
+ }
|
|
|
+ ),
|
|
|
+ )
|
|
|
+
|
|
|
+ return 0
|
|
|
+
|
|
|
+
|
|
|
+if __name__ == "__main__":
|
|
|
+ sys.exit(main())
|