From 416834f6e51a54320ee7a209d5aa00bbad2d43f0 Mon Sep 17 00:00:00 2001 From: Qiu-IT Date: Fri, 4 Aug 2023 17:22:34 +0200 Subject: [PATCH 1/5] feat: add pandas py solution to lc problem: No.1757 --- .../1757.Recyclable and Low Fat Products/README.md | 9 +++++++++ .../1757.Recyclable and Low Fat Products/README_EN.md | 10 ++++++++++ .../1757.Recyclable and Low Fat Products/Solution.py | 5 +++++ 3 files changed, 24 insertions(+) create mode 100644 solution/1700-1799/1757.Recyclable and Low Fat Products/Solution.py diff --git a/solution/1700-1799/1757.Recyclable and Low Fat Products/README.md b/solution/1700-1799/1757.Recyclable and Low Fat Products/README.md index f26afaa90adca..41b35228f2af9 100644 --- a/solution/1700-1799/1757.Recyclable and Low Fat Products/README.md +++ b/solution/1700-1799/1757.Recyclable and Low Fat Products/README.md @@ -64,4 +64,13 @@ FROM Products WHERE low_fats = 'Y' AND recyclable = 'Y'; ``` +### **PANDAS** + +```py +import pandas as pd +def find_products(products: pd.DataFrame) -> pd.DataFrame: + rs = products[(products['low_fats'] == 'Y') & (products['recyclable'] == 'Y')] + rs = rs[['product_id']] + return rs +``` diff --git a/solution/1700-1799/1757.Recyclable and Low Fat Products/README_EN.md b/solution/1700-1799/1757.Recyclable and Low Fat Products/README_EN.md index 4b078e3fa825c..605c1813649fe 100644 --- a/solution/1700-1799/1757.Recyclable and Low Fat Products/README_EN.md +++ b/solution/1700-1799/1757.Recyclable and Low Fat Products/README_EN.md @@ -64,4 +64,14 @@ FROM Products WHERE low_fats = 'Y' AND recyclable = 'Y'; ``` +### **PANDAS** + +```py +import pandas as pd +def find_products(products: pd.DataFrame) -> pd.DataFrame: + rs = products[(products['low_fats'] == 'Y') & (products['recyclable'] == 'Y')] + rs = rs[['product_id']] + return rs +``` + diff --git a/solution/1700-1799/1757.Recyclable and Low Fat Products/Solution.py b/solution/1700-1799/1757.Recyclable and Low Fat Products/Solution.py new file mode 100644 index 0000000000000..fb8482918e05e --- /dev/null +++ b/solution/1700-1799/1757.Recyclable and Low Fat Products/Solution.py @@ -0,0 +1,5 @@ +import pandas as pd +def find_products(products: pd.DataFrame) -> pd.DataFrame: + rs = products[(products['low_fats'] == 'Y') & (products['recyclable'] == 'Y')] + rs = rs[['product_id']] + return rs \ No newline at end of file From 0e807738cced9c81f919246aefd8c9c77dfb0342 Mon Sep 17 00:00:00 2001 From: Yang Libin Date: Sat, 5 Aug 2023 10:45:37 +0800 Subject: [PATCH 2/5] Update README.md --- .../1757.Recyclable and Low Fat Products/README.md | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/solution/1700-1799/1757.Recyclable and Low Fat Products/README.md b/solution/1700-1799/1757.Recyclable and Low Fat Products/README.md index 41b35228f2af9..57ebdfc5ff059 100644 --- a/solution/1700-1799/1757.Recyclable and Low Fat Products/README.md +++ b/solution/1700-1799/1757.Recyclable and Low Fat Products/README.md @@ -66,11 +66,14 @@ WHERE low_fats = 'Y' AND recyclable = 'Y'; ### **PANDAS** -```py +```python import pandas as pd + + def find_products(products: pd.DataFrame) -> pd.DataFrame: - rs = products[(products['low_fats'] == 'Y') & (products['recyclable'] == 'Y')] - rs = rs[['product_id']] + rs = products[(products["low_fats"] == "Y") & (products["recyclable"] == "Y")] + rs = rs[["product_id"]] return rs ``` + From 1435cb9f0f82d0cc1576922753891b1cb874dcc3 Mon Sep 17 00:00:00 2001 From: Yang Libin Date: Sat, 5 Aug 2023 10:45:55 +0800 Subject: [PATCH 3/5] Update Solution.py --- .../1757.Recyclable and Low Fat Products/Solution.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/solution/1700-1799/1757.Recyclable and Low Fat Products/Solution.py b/solution/1700-1799/1757.Recyclable and Low Fat Products/Solution.py index fb8482918e05e..01b0f3850eaeb 100644 --- a/solution/1700-1799/1757.Recyclable and Low Fat Products/Solution.py +++ b/solution/1700-1799/1757.Recyclable and Low Fat Products/Solution.py @@ -1,5 +1,7 @@ import pandas as pd + + def find_products(products: pd.DataFrame) -> pd.DataFrame: - rs = products[(products['low_fats'] == 'Y') & (products['recyclable'] == 'Y')] - rs = rs[['product_id']] - return rs \ No newline at end of file + rs = products[(products["low_fats"] == "Y") & (products["recyclable"] == "Y")] + rs = rs[["product_id"]] + return rs From 9c274abec4cecdcdbecaf90c2e9688de4898de1a Mon Sep 17 00:00:00 2001 From: Yang Libin Date: Sat, 5 Aug 2023 10:46:22 +0800 Subject: [PATCH 4/5] Update README_EN.md --- .../1757.Recyclable and Low Fat Products/README_EN.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/solution/1700-1799/1757.Recyclable and Low Fat Products/README_EN.md b/solution/1700-1799/1757.Recyclable and Low Fat Products/README_EN.md index 605c1813649fe..6d6561ea3c701 100644 --- a/solution/1700-1799/1757.Recyclable and Low Fat Products/README_EN.md +++ b/solution/1700-1799/1757.Recyclable and Low Fat Products/README_EN.md @@ -68,9 +68,11 @@ WHERE low_fats = 'Y' AND recyclable = 'Y'; ```py import pandas as pd + + def find_products(products: pd.DataFrame) -> pd.DataFrame: - rs = products[(products['low_fats'] == 'Y') & (products['recyclable'] == 'Y')] - rs = rs[['product_id']] + rs = products[(products["low_fats"] == "Y") & (products["recyclable"] == "Y")] + rs = rs[["product_id"]] return rs ``` From 9e992fbc3c85c296d2f2b61508858977e0bc2a80 Mon Sep 17 00:00:00 2001 From: Yang Libin Date: Sat, 5 Aug 2023 10:47:45 +0800 Subject: [PATCH 5/5] Update README_EN.md --- .../1700-1799/1757.Recyclable and Low Fat Products/README_EN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/solution/1700-1799/1757.Recyclable and Low Fat Products/README_EN.md b/solution/1700-1799/1757.Recyclable and Low Fat Products/README_EN.md index 6d6561ea3c701..904cb8c31bede 100644 --- a/solution/1700-1799/1757.Recyclable and Low Fat Products/README_EN.md +++ b/solution/1700-1799/1757.Recyclable and Low Fat Products/README_EN.md @@ -66,7 +66,7 @@ WHERE low_fats = 'Y' AND recyclable = 'Y'; ### **PANDAS** -```py +```python import pandas as pd