Skip to content

Commit 9763c5a

Browse files
committed
Adjust indentation
1 parent fbc840d commit 9763c5a

File tree

2 files changed

+76
-4
lines changed

2 files changed

+76
-4
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
"""
2+
183. Customers Who Never Order
3+
Solved
4+
Easy
5+
Topics
6+
Companies
7+
SQL Schema
8+
Pandas Schema
9+
10+
Table: Customers
11+
12+
+-------------+---------+
13+
| Column Name | Type |
14+
+-------------+---------+
15+
| id | int |
16+
| name | varchar |
17+
+-------------+---------+
18+
id is the primary key (column with unique values) for this table.
19+
Each row of this table indicates the ID and name of a customer.
20+
21+
Table: Orders
22+
23+
+-------------+------+
24+
| Column Name | Type |
25+
+-------------+------+
26+
| id | int |
27+
| customerId | int |
28+
+-------------+------+
29+
id is the primary key (column with unique values) for this table.
30+
customerId is a foreign key (reference columns) of the ID from the Customers table.
31+
Each row of this table indicates the ID of an order and the ID of the customer who ordered it.
32+
33+
Write a solution to find all customers who never order anything.
34+
35+
Return the result table in any order.
36+
37+
The result format is in the following example.
38+
39+
Example 1:
40+
41+
Input:
42+
Customers table:
43+
+----+-------+
44+
| id | name |
45+
+----+-------+
46+
| 1 | Joe |
47+
| 2 | Henry |
48+
| 3 | Sam |
49+
| 4 | Max |
50+
+----+-------+
51+
Orders table:
52+
+----+------------+
53+
| id | customerId |
54+
+----+------------+
55+
| 1 | 3 |
56+
| 2 | 1 |
57+
+----+------------+
58+
Output:
59+
+-----------+
60+
| Customers |
61+
+-----------+
62+
| Henry |
63+
| Max |
64+
+-----------+
65+
"""
66+
67+
import pandas as pd
68+
69+
def find_customers(customers: pd.DataFrame, orders: pd.DataFrame) -> pd.DataFrame:
70+
# get all possible customers and their orders
71+
merged_df = customers.merge(orders, left_on = 'id', right_on = 'customerId', how = 'left')
72+
73+
# only keep those who were not in the 'orders' table and renaming the 'name' column
74+
customers_df = merged_df[merged_df['customerId'].isnull()][['name']].rename(columns={'name': 'Customers'})
75+
76+
return customers_df

30_days_pandas/1757_recyclable_products.py

-4
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,12 @@
2020
low_fats is an ENUM (category) of type ('Y', 'N') where 'Y' means this product is low fat and 'N' means it is not.
2121
recyclable is an ENUM (category) of types ('Y', 'N') where 'Y' means this product is recyclable and 'N' means it is not.
2222
23-
24-
2523
Write a solution to find the ids of products that are both low fat and recyclable.
2624
2725
Return the result table in any order.
2826
2927
The result format is in the following example.
3028
31-
32-
3329
Example 1:
3430
3531
Input:

0 commit comments

Comments
 (0)