File tree 3 files changed +59
-0
lines changed
3 files changed +59
-0
lines changed File renamed without changes.
Original file line number Diff line number Diff line change
1
+ """
2
+ 1757. Recyclable and Low Fat Products
3
+ Solved
4
+ Easy
5
+ Topics
6
+ Companies
7
+ SQL Schema
8
+ Pandas Schema
9
+
10
+ Table: Products
11
+
12
+ +-------------+---------+
13
+ | Column Name | Type |
14
+ +-------------+---------+
15
+ | product_id | int |
16
+ | low_fats | enum |
17
+ | recyclable | enum |
18
+ +-------------+---------+
19
+ product_id is the primary key (column with unique values) for this table.
20
+ low_fats is an ENUM (category) of type ('Y', 'N') where 'Y' means this product is low fat and 'N' means it is not.
21
+ recyclable is an ENUM (category) of types ('Y', 'N') where 'Y' means this product is recyclable and 'N' means it is not.
22
+
23
+
24
+
25
+ Write a solution to find the ids of products that are both low fat and recyclable.
26
+
27
+ Return the result table in any order.
28
+
29
+ The result format is in the following example.
30
+
31
+
32
+
33
+ Example 1:
34
+
35
+ Input:
36
+ Products table:
37
+ +-------------+----------+------------+
38
+ | product_id | low_fats | recyclable |
39
+ +-------------+----------+------------+
40
+ | 0 | Y | N |
41
+ | 1 | Y | Y |
42
+ | 2 | N | Y |
43
+ | 3 | Y | Y |
44
+ | 4 | N | N |
45
+ +-------------+----------+------------+
46
+ Output:
47
+ +-------------+
48
+ | product_id |
49
+ +-------------+
50
+ | 1 |
51
+ | 3 |
52
+ +-------------+
53
+ Explanation: Only products 1 and 3 are both low fat and recyclable.
54
+ """
55
+
56
+ import pandas as pd
57
+
58
+ def find_products (products : pd .DataFrame ) -> pd .DataFrame :
59
+ return products [(products ['low_fats' ] == 'Y' ) & (products ['recyclable' ] == 'Y' )][['product_id' ]]
You can’t perform that action at this time.
0 commit comments