Skip to content

Commit 4de9712

Browse files
authored
feat: add pandas solutions to lc problems: No.0182,0183 (#1868)
1 parent e26ff97 commit 4de9712

File tree

6 files changed

+76
-0
lines changed

6 files changed

+76
-0
lines changed

solution/0100-0199/0182.Duplicate Emails/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -83,4 +83,17 @@ FROM
8383
WHERE p1.id != p2.id AND p1.email = p2.email;
8484
```
8585

86+
```python
87+
import pandas as pd
88+
89+
90+
def duplicate_emails(person: pd.DataFrame) -> pd.DataFrame:
91+
results = pd.DataFrame()
92+
93+
results = person.loc[person.duplicated(subset=["email"]), ["email"]]
94+
95+
return results.drop_duplicates()
96+
97+
```
98+
8699
<!-- tabs:end -->

solution/0100-0199/0182.Duplicate Emails/README_EN.md

+13
Original file line numberDiff line numberDiff line change
@@ -77,4 +77,17 @@ FROM
7777
WHERE p1.id != p2.id AND p1.email = p2.email;
7878
```
7979

80+
```python
81+
import pandas as pd
82+
83+
84+
def duplicate_emails(person: pd.DataFrame) -> pd.DataFrame:
85+
results = pd.DataFrame()
86+
87+
results = person.loc[person.duplicated(subset=["email"]), ["email"]]
88+
89+
return results.drop_duplicates()
90+
91+
```
92+
8093
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import pandas as pd
2+
3+
4+
def duplicate_emails(person: pd.DataFrame) -> pd.DataFrame:
5+
results = pd.DataFrame()
6+
7+
results = person.loc[person.duplicated(subset=["email"]), ["email"]]
8+
9+
return results.drop_duplicates()

solution/0100-0199/0183.Customers Who Never Order/README.md

+15
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,19 @@ FROM
105105
WHERE o.id IS NULL;
106106
```
107107

108+
```python
109+
import pandas as pd
110+
111+
112+
def find_customers(customers: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFrame:
113+
# Select the customers whose 'id' is not present in the orders DataFrame's 'customerId' column.
114+
df = customers[~customers["id"].isin(orders["customerId"])]
115+
116+
# Build a DataFrame that only contains the 'name' column and rename it as 'Customers'.
117+
df = df[["name"]].rename(columns={"name": "Customers"})
118+
119+
return df
120+
121+
```
122+
108123
<!-- tabs:end -->

solution/0100-0199/0183.Customers Who Never Order/README_EN.md

+15
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,19 @@ FROM
105105
WHERE o.id IS NULL;
106106
```
107107

108+
```python
109+
import pandas as pd
110+
111+
112+
def find_customers(customers: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFrame:
113+
# Select the customers whose 'id' is not present in the orders DataFrame's 'customerId' column.
114+
df = customers[~customers["id"].isin(orders["customerId"])]
115+
116+
# Build a DataFrame that only contains the 'name' column and rename it as 'Customers'.
117+
df = df[["name"]].rename(columns={"name": "Customers"})
118+
119+
return df
120+
121+
```
122+
108123
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import pandas as pd
2+
3+
4+
def find_customers(customers: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFrame:
5+
# Select the customers whose 'id' is not present in the orders DataFrame's 'customerId' column.
6+
df = customers[~customers["id"].isin(orders["customerId"])]
7+
8+
# Build a DataFrame that only contains the 'name' column and rename it as 'Customers'.
9+
df = df[["name"]].rename(columns={"name": "Customers"})
10+
11+
return df

0 commit comments

Comments
 (0)