From 0f5e4348156995486e587bcd2f3ee19486a1c26f Mon Sep 17 00:00:00 2001 From: Yang Libin Date: Wed, 4 Oct 2023 02:23:11 +0000 Subject: [PATCH] chore: add new lc problems --- .../README.md | 60 ++++++++++++ .../README_EN.md | 54 +++++++++++ .../README.md | 75 +++++++++++++++ .../README_EN.md | 69 ++++++++++++++ .../README.md | 70 ++++++++++++++ .../README_EN.md | 64 +++++++++++++ solution/2800-2899/2880.Select Data/README.md | 86 ++++++++++++++++++ .../2800-2899/2880.Select Data/README_EN.md | 60 ++++++++++++ .../2881.Create a New Column/README.md | 75 +++++++++++++++ .../2881.Create a New Column/README_EN.md | 69 ++++++++++++++ .../2882.Drop Duplicate Rows/README.md | 74 +++++++++++++++ .../2882.Drop Duplicate Rows/README_EN.md | 68 ++++++++++++++ .../2883.Drop Missing Data/README.md | 69 ++++++++++++++ .../2883.Drop Missing Data/README_EN.md | 63 +++++++++++++ .../2800-2899/2884.Modify Columns/README.md | 91 +++++++++++++++++++ .../2884.Modify Columns/README_EN.md | 65 +++++++++++++ .../2800-2899/2885.Rename Columns/README.md | 78 ++++++++++++++++ .../2885.Rename Columns/README_EN.md | 72 +++++++++++++++ .../2800-2899/2886.Change Data Type/README.md | 68 ++++++++++++++ .../2886.Change Data Type/README_EN.md | 62 +++++++++++++ .../2887.Fill Missing Data/README.md | 67 ++++++++++++++ .../2887.Fill Missing Data/README_EN.md | 61 +++++++++++++ .../2888.Reshape Data Concatenate/README.md | 89 ++++++++++++++++++ .../README_EN.md | 83 +++++++++++++++++ .../2889.Reshape Data Pivot/README.md | 75 +++++++++++++++ .../2889.Reshape Data Pivot/README_EN.md | 69 ++++++++++++++ .../2890.Reshape Data Melt/README.md | 74 +++++++++++++++ .../2890.Reshape Data Melt/README_EN.md | 68 ++++++++++++++ .../2800-2899/2891.Method Chaining/README.md | 82 +++++++++++++++++ .../2891.Method Chaining/README_EN.md | 76 ++++++++++++++++ solution/README.md | 15 +++ solution/README_EN.md | 15 +++ solution/summary.md | 15 +++ solution/summary_en.md | 15 +++ 34 files changed, 2196 insertions(+) create mode 100644 solution/2800-2899/2877.Create a DataFrame from List/README.md create mode 100644 solution/2800-2899/2877.Create a DataFrame from List/README_EN.md create mode 100644 solution/2800-2899/2878.Get the Size of a DataFrame/README.md create mode 100644 solution/2800-2899/2878.Get the Size of a DataFrame/README_EN.md create mode 100644 solution/2800-2899/2879.Display the First Three Rows/README.md create mode 100644 solution/2800-2899/2879.Display the First Three Rows/README_EN.md create mode 100644 solution/2800-2899/2880.Select Data/README.md create mode 100644 solution/2800-2899/2880.Select Data/README_EN.md create mode 100644 solution/2800-2899/2881.Create a New Column/README.md create mode 100644 solution/2800-2899/2881.Create a New Column/README_EN.md create mode 100644 solution/2800-2899/2882.Drop Duplicate Rows/README.md create mode 100644 solution/2800-2899/2882.Drop Duplicate Rows/README_EN.md create mode 100644 solution/2800-2899/2883.Drop Missing Data/README.md create mode 100644 solution/2800-2899/2883.Drop Missing Data/README_EN.md create mode 100644 solution/2800-2899/2884.Modify Columns/README.md create mode 100644 solution/2800-2899/2884.Modify Columns/README_EN.md create mode 100644 solution/2800-2899/2885.Rename Columns/README.md create mode 100644 solution/2800-2899/2885.Rename Columns/README_EN.md create mode 100644 solution/2800-2899/2886.Change Data Type/README.md create mode 100644 solution/2800-2899/2886.Change Data Type/README_EN.md create mode 100644 solution/2800-2899/2887.Fill Missing Data/README.md create mode 100644 solution/2800-2899/2887.Fill Missing Data/README_EN.md create mode 100644 solution/2800-2899/2888.Reshape Data Concatenate/README.md create mode 100644 solution/2800-2899/2888.Reshape Data Concatenate/README_EN.md create mode 100644 solution/2800-2899/2889.Reshape Data Pivot/README.md create mode 100644 solution/2800-2899/2889.Reshape Data Pivot/README_EN.md create mode 100644 solution/2800-2899/2890.Reshape Data Melt/README.md create mode 100644 solution/2800-2899/2890.Reshape Data Melt/README_EN.md create mode 100644 solution/2800-2899/2891.Method Chaining/README.md create mode 100644 solution/2800-2899/2891.Method Chaining/README_EN.md diff --git a/solution/2800-2899/2877.Create a DataFrame from List/README.md b/solution/2800-2899/2877.Create a DataFrame from List/README.md new file mode 100644 index 0000000000000..c3cbec94df8e0 --- /dev/null +++ b/solution/2800-2899/2877.Create a DataFrame from List/README.md @@ -0,0 +1,60 @@ +# [2877. Create a DataFrame from List](https://leetcode.cn/problems/create-a-dataframe-from-list) + +[English Version](/solution/2800-2899/2877.Create%20a%20DataFrame%20from%20List/README_EN.md) + +## 题目描述 + + + +

Write a solution to create a DataFrame from a 2D list called student_data. This 2D list contains the IDs and ages of some students.

+ +

The DataFrame should have two columns, student_id and age, and be in the same order as the original 2D list.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
+student_data:
+[
+  [1, 15],
+  [2, 11],
+  [3, 11],
+  [4, 20]
+]
+Output:
++------------+-----+
+| student_id | age |
++------------+-----+
+| 1          | 15  |
+| 2          | 11  |
+| 3          | 11  |
+| 4          | 20  |
++------------+-----+
+Explanation:
+A DataFrame was created on top of student_data, with two columns named student_id and age.
+
+ +## 解法 + + + + + +### **Pandas** + + + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2877.Create a DataFrame from List/README_EN.md b/solution/2800-2899/2877.Create a DataFrame from List/README_EN.md new file mode 100644 index 0000000000000..6c0894a9977e8 --- /dev/null +++ b/solution/2800-2899/2877.Create a DataFrame from List/README_EN.md @@ -0,0 +1,54 @@ +# [2877. Create a DataFrame from List](https://leetcode.com/problems/create-a-dataframe-from-list) + +[中文文档](/solution/2800-2899/2877.Create%20a%20DataFrame%20from%20List/README.md) + +## Description + +

Write a solution to create a DataFrame from a 2D list called student_data. This 2D list contains the IDs and ages of some students.

+ +

The DataFrame should have two columns, student_id and age, and be in the same order as the original 2D list.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
+student_data:
+[
+  [1, 15],
+  [2, 11],
+  [3, 11],
+  [4, 20]
+]
+Output:
++------------+-----+
+| student_id | age |
++------------+-----+
+| 1          | 15  |
+| 2          | 11  |
+| 3          | 11  |
+| 4          | 20  |
++------------+-----+
+Explanation:
+A DataFrame was created on top of student_data, with two columns named student_id and age.
+
+ +## Solutions + + + +### **Pandas** + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2878.Get the Size of a DataFrame/README.md b/solution/2800-2899/2878.Get the Size of a DataFrame/README.md new file mode 100644 index 0000000000000..01e4a566d9513 --- /dev/null +++ b/solution/2800-2899/2878.Get the Size of a DataFrame/README.md @@ -0,0 +1,75 @@ +# [2878. Get the Size of a DataFrame](https://leetcode.cn/problems/get-the-size-of-a-dataframe) + +[English Version](/solution/2800-2899/2878.Get%20the%20Size%20of%20a%20DataFrame/README_EN.md) + +## 题目描述 + + + +
+DataFrame players:
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| player_id   | int    |
+| name        | object |
+| age         | int    |
+| position    | object |
+| ...         | ...    |
++-------------+--------+
+
+ +

Write a solution to calculate and display the number of rows and columns of players.

+ +

Return the result as an array:

+ +

[number of rows, number of columns]

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
++-----------+----------+-----+-------------+--------------------+
+| player_id | name     | age | position    | team               |
++-----------+----------+-----+-------------+--------------------+
+| 846       | Mason    | 21  | Forward     | RealMadrid         |
+| 749       | Riley    | 30  | Winger      | Barcelona          |
+| 155       | Bob      | 28  | Striker     | ManchesterUnited   |
+| 583       | Isabella | 32  | Goalkeeper  | Liverpool          |
+| 388       | Zachary  | 24  | Midfielder  | BayernMunich       |
+| 883       | Ava      | 23  | Defender    | Chelsea            |
+| 355       | Violet   | 18  | Striker     | Juventus           |
+| 247       | Thomas   | 27  | Striker     | ParisSaint-Germain |
+| 761       | Jack     | 33  | Midfielder  | ManchesterCity     |
+| 642       | Charlie  | 36  | Center-back | Arsenal            |
++-----------+----------+-----+-------------+--------------------+
+Output:
+[10, 5]
+Explanation:
+This DataFrame contains 10 rows and 5 columns.
+
+ +## 解法 + + + + + +### **Pandas** + + + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2878.Get the Size of a DataFrame/README_EN.md b/solution/2800-2899/2878.Get the Size of a DataFrame/README_EN.md new file mode 100644 index 0000000000000..7d6d2263ed958 --- /dev/null +++ b/solution/2800-2899/2878.Get the Size of a DataFrame/README_EN.md @@ -0,0 +1,69 @@ +# [2878. Get the Size of a DataFrame](https://leetcode.com/problems/get-the-size-of-a-dataframe) + +[中文文档](/solution/2800-2899/2878.Get%20the%20Size%20of%20a%20DataFrame/README.md) + +## Description + +
+DataFrame players:
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| player_id   | int    |
+| name        | object |
+| age         | int    |
+| position    | object |
+| ...         | ...    |
++-------------+--------+
+
+ +

Write a solution to calculate and display the number of rows and columns of players.

+ +

Return the result as an array:

+ +

[number of rows, number of columns]

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
++-----------+----------+-----+-------------+--------------------+
+| player_id | name     | age | position    | team               |
++-----------+----------+-----+-------------+--------------------+
+| 846       | Mason    | 21  | Forward     | RealMadrid         |
+| 749       | Riley    | 30  | Winger      | Barcelona          |
+| 155       | Bob      | 28  | Striker     | ManchesterUnited   |
+| 583       | Isabella | 32  | Goalkeeper  | Liverpool          |
+| 388       | Zachary  | 24  | Midfielder  | BayernMunich       |
+| 883       | Ava      | 23  | Defender    | Chelsea            |
+| 355       | Violet   | 18  | Striker     | Juventus           |
+| 247       | Thomas   | 27  | Striker     | ParisSaint-Germain |
+| 761       | Jack     | 33  | Midfielder  | ManchesterCity     |
+| 642       | Charlie  | 36  | Center-back | Arsenal            |
++-----------+----------+-----+-------------+--------------------+
+Output:
+[10, 5]
+Explanation:
+This DataFrame contains 10 rows and 5 columns.
+
+ +## Solutions + + + +### **Pandas** + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2879.Display the First Three Rows/README.md b/solution/2800-2899/2879.Display the First Three Rows/README.md new file mode 100644 index 0000000000000..e8f79e7fbe8b8 --- /dev/null +++ b/solution/2800-2899/2879.Display the First Three Rows/README.md @@ -0,0 +1,70 @@ +# [2879. Display the First Three Rows](https://leetcode.cn/problems/display-the-first-three-rows) + +[English Version](/solution/2800-2899/2879.Display%20the%20First%20Three%20Rows/README_EN.md) + +## 题目描述 + + + +
+DataFrame: employees
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| employee_id | int    |
+| name        | object |
+| department  | object |
+| salary      | int    |
++-------------+--------+
+
+ +

Write a solution to display the first 3 rows of this DataFrame.

+ +

 

+

Example 1:

+ +
+Input:
+DataFrame employees
++-------------+-----------+-----------------------+--------+
+| employee_id | name      | department            | salary |
++-------------+-----------+-----------------------+--------+
+| 3           | Bob       | Operations            | 48675  |
+| 90          | Alice     | Sales                 | 11096  |
+| 9           | Tatiana   | Engineering           | 33805  |
+| 60          | Annabelle | InformationTechnology | 37678  |
+| 49          | Jonathan  | HumanResources        | 23793  |
+| 43          | Khaled    | Administration        | 40454  |
++-------------+-----------+-----------------------+--------+
+Output:
++-------------+---------+-------------+--------+
+| employee_id | name    | department  | salary |
++-------------+---------+-------------+--------+
+| 3           | Bob     | Operations  | 48675  |
+| 90          | Alice   | Sales       | 11096  |
+| 9           | Tatiana | Engineering | 33805  |
++-------------+---------+-------------+--------+
+Explanation: 
+Only the first 3 rows are displayed.
+ +## 解法 + + + + + +### **Pandas** + + + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2879.Display the First Three Rows/README_EN.md b/solution/2800-2899/2879.Display the First Three Rows/README_EN.md new file mode 100644 index 0000000000000..f0725ff5a9630 --- /dev/null +++ b/solution/2800-2899/2879.Display the First Three Rows/README_EN.md @@ -0,0 +1,64 @@ +# [2879. Display the First Three Rows](https://leetcode.com/problems/display-the-first-three-rows) + +[中文文档](/solution/2800-2899/2879.Display%20the%20First%20Three%20Rows/README.md) + +## Description + +
+DataFrame: employees
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| employee_id | int    |
+| name        | object |
+| department  | object |
+| salary      | int    |
++-------------+--------+
+
+ +

Write a solution to display the first 3 rows of this DataFrame.

+ +

 

+

Example 1:

+ +
+Input:
+DataFrame employees
++-------------+-----------+-----------------------+--------+
+| employee_id | name      | department            | salary |
++-------------+-----------+-----------------------+--------+
+| 3           | Bob       | Operations            | 48675  |
+| 90          | Alice     | Sales                 | 11096  |
+| 9           | Tatiana   | Engineering           | 33805  |
+| 60          | Annabelle | InformationTechnology | 37678  |
+| 49          | Jonathan  | HumanResources        | 23793  |
+| 43          | Khaled    | Administration        | 40454  |
++-------------+-----------+-----------------------+--------+
+Output:
++-------------+---------+-------------+--------+
+| employee_id | name    | department  | salary |
++-------------+---------+-------------+--------+
+| 3           | Bob     | Operations  | 48675  |
+| 90          | Alice   | Sales       | 11096  |
+| 9           | Tatiana | Engineering | 33805  |
++-------------+---------+-------------+--------+
+Explanation: 
+Only the first 3 rows are displayed.
+ +## Solutions + + + +### **Pandas** + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2880.Select Data/README.md b/solution/2800-2899/2880.Select Data/README.md new file mode 100644 index 0000000000000..28b3d52a43f1d --- /dev/null +++ b/solution/2800-2899/2880.Select Data/README.md @@ -0,0 +1,86 @@ +# [2880. Select Data](https://leetcode.cn/problems/select-data) + +[English Version](/solution/2800-2899/2880.Select%20Data/README_EN.md) + +## 题目描述 + + + +
+DataFrame students
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
++-------------+--------+
+
+
+ +

Write a solution to select the name and age of the student with student_id = 101.

+ +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:
++------------+---------+-----+
+| student_id | name    | age |
++------------+---------+-----+
+| 101        | Ulysses | 13  |
+| 53         | William | 10  |
+| 128        | Henry   | 6   |
+| 3          | Henry   | 11  |
++------------+---------+-----+
+Output:
++---------+-----+
+| name    | age | 
++---------+-----+
+| Ulysses | 13  |
++---------+-----+
+Explanation:
+Student Ulysses has student_id = 101, we select the name and age.
+ +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2880.Select Data/README_EN.md b/solution/2800-2899/2880.Select Data/README_EN.md new file mode 100644 index 0000000000000..bd9357644ec84 --- /dev/null +++ b/solution/2800-2899/2880.Select Data/README_EN.md @@ -0,0 +1,60 @@ +# [2880. Select Data](https://leetcode.com/problems/select-data) + +[中文文档](/solution/2800-2899/2880.Select%20Data/README.md) + +## Description + +
+DataFrame students
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
++-------------+--------+
+
+
+ +

Write a solution to select the name and age of the student with student_id = 101.

+ +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:
++------------+---------+-----+
+| student_id | name    | age |
++------------+---------+-----+
+| 101        | Ulysses | 13  |
+| 53         | William | 10  |
+| 128        | Henry   | 6   |
+| 3          | Henry   | 11  |
++------------+---------+-----+
+Output:
++---------+-----+
+| name    | age | 
++---------+-----+
+| Ulysses | 13  |
++---------+-----+
+Explanation:
+Student Ulysses has student_id = 101, we select the name and age.
+ +## Solutions + + + +### **Pandas** + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2881.Create a New Column/README.md b/solution/2800-2899/2881.Create a New Column/README.md new file mode 100644 index 0000000000000..e27a06082ec1b --- /dev/null +++ b/solution/2800-2899/2881.Create a New Column/README.md @@ -0,0 +1,75 @@ +# [2881. Create a New Column](https://leetcode.cn/problems/create-a-new-column) + +[English Version](/solution/2800-2899/2881.Create%20a%20New%20Column/README_EN.md) + +## 题目描述 + + + +
+DataFrame employees
++-------------+--------+
+| Column Name | Type.  |
++-------------+--------+
+| name        | object |
+| salary      | int.   |
++-------------+--------+
+
+ +

A company plans to provide its employees with a bonus.

+ +

Write a solution to create a new column name bonus that contains the doubled values of the salary column.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
+DataFrame employees
++---------+--------+
+| name    | salary |
++---------+--------+
+| Piper   | 4548   |
+| Grace   | 28150  |
+| Georgia | 1103   |
+| Willow  | 6593   |
+| Finn    | 74576  |
+| Thomas  | 24433  |
++---------+--------+
+Output:
++---------+--------+--------+
+| name    | salary | bonus  |
++---------+--------+--------+
+| Piper   | 4548   | 9096   |
+| Grace   | 28150  | 56300  |
+| Georgia | 1103   | 2206   |
+| Willow  |  593   | 13186  |
+| Finn    | 74576  | 149152 |
+| Thomas  | 24433  | 48866  |
++---------+--------+--------+
+Explanation: 
+A new column bonus is created by doubling the value in the column salary.
+ +## 解法 + + + + + +### **Pandas** + + + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2881.Create a New Column/README_EN.md b/solution/2800-2899/2881.Create a New Column/README_EN.md new file mode 100644 index 0000000000000..ca6a8ff59a627 --- /dev/null +++ b/solution/2800-2899/2881.Create a New Column/README_EN.md @@ -0,0 +1,69 @@ +# [2881. Create a New Column](https://leetcode.com/problems/create-a-new-column) + +[中文文档](/solution/2800-2899/2881.Create%20a%20New%20Column/README.md) + +## Description + +
+DataFrame employees
++-------------+--------+
+| Column Name | Type.  |
++-------------+--------+
+| name        | object |
+| salary      | int.   |
++-------------+--------+
+
+ +

A company plans to provide its employees with a bonus.

+ +

Write a solution to create a new column name bonus that contains the doubled values of the salary column.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
+DataFrame employees
++---------+--------+
+| name    | salary |
++---------+--------+
+| Piper   | 4548   |
+| Grace   | 28150  |
+| Georgia | 1103   |
+| Willow  | 6593   |
+| Finn    | 74576  |
+| Thomas  | 24433  |
++---------+--------+
+Output:
++---------+--------+--------+
+| name    | salary | bonus  |
++---------+--------+--------+
+| Piper   | 4548   | 9096   |
+| Grace   | 28150  | 56300  |
+| Georgia | 1103   | 2206   |
+| Willow  |  593   | 13186  |
+| Finn    | 74576  | 149152 |
+| Thomas  | 24433  | 48866  |
++---------+--------+--------+
+Explanation: 
+A new column bonus is created by doubling the value in the column salary.
+ +## Solutions + + + +### **Pandas** + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2882.Drop Duplicate Rows/README.md b/solution/2800-2899/2882.Drop Duplicate Rows/README.md new file mode 100644 index 0000000000000..e98820961329e --- /dev/null +++ b/solution/2800-2899/2882.Drop Duplicate Rows/README.md @@ -0,0 +1,74 @@ +# [2882. Drop Duplicate Rows](https://leetcode.cn/problems/drop-duplicate-rows) + +[English Version](/solution/2800-2899/2882.Drop%20Duplicate%20Rows/README_EN.md) + +## 题目描述 + + + +
+DataFrame customers
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| customer_id | int    |
+| name        | object |
+| email       | object |
++-------------+--------+
+
+ +

There are some duplicate rows in the DataFrame based on the email column.

+ +

Write a solution to remove these duplicate rows and keep only the first occurrence.

+ +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:
++-------------+---------+---------------------+
+| customer_id | name    | email               |
++-------------+---------+---------------------+
+| 1           | Ella    | emily@example.com   |
+| 2           | David   | michael@example.com |
+| 3           | Zachary | sarah@example.com   |
+| 4           | Alice   | john@example.com    |
+| 5           | Finn    | john@example.com    |
+| 6           | Violet  | alice@example.com   |
++-------------+---------+---------------------+
+Output:  
++-------------+---------+---------------------+
+| customer_id | name    | email               |
++-------------+---------+---------------------+
+| 1           | Ella    | emily@example.com   |
+| 2           | David   | michael@example.com |
+| 3           | Zachary | sarah@example.com   |
+| 4           | Alice   | john@example.com    |
+| 6           | Violet  | alice@example.com   |
++-------------+---------+---------------------+
+Explanation:
+Alic (customer_id = 4) and Finn (customer_id = 5) both use john@example.com, so only the first occurrence of this email is retained.
+
+ +## 解法 + + + + + +### **Pandas** + + + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2882.Drop Duplicate Rows/README_EN.md b/solution/2800-2899/2882.Drop Duplicate Rows/README_EN.md new file mode 100644 index 0000000000000..a89fec2792e73 --- /dev/null +++ b/solution/2800-2899/2882.Drop Duplicate Rows/README_EN.md @@ -0,0 +1,68 @@ +# [2882. Drop Duplicate Rows](https://leetcode.com/problems/drop-duplicate-rows) + +[中文文档](/solution/2800-2899/2882.Drop%20Duplicate%20Rows/README.md) + +## Description + +
+DataFrame customers
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| customer_id | int    |
+| name        | object |
+| email       | object |
++-------------+--------+
+
+ +

There are some duplicate rows in the DataFrame based on the email column.

+ +

Write a solution to remove these duplicate rows and keep only the first occurrence.

+ +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:
++-------------+---------+---------------------+
+| customer_id | name    | email               |
++-------------+---------+---------------------+
+| 1           | Ella    | emily@example.com   |
+| 2           | David   | michael@example.com |
+| 3           | Zachary | sarah@example.com   |
+| 4           | Alice   | john@example.com    |
+| 5           | Finn    | john@example.com    |
+| 6           | Violet  | alice@example.com   |
++-------------+---------+---------------------+
+Output:  
++-------------+---------+---------------------+
+| customer_id | name    | email               |
++-------------+---------+---------------------+
+| 1           | Ella    | emily@example.com   |
+| 2           | David   | michael@example.com |
+| 3           | Zachary | sarah@example.com   |
+| 4           | Alice   | john@example.com    |
+| 6           | Violet  | alice@example.com   |
++-------------+---------+---------------------+
+Explanation:
+Alic (customer_id = 4) and Finn (customer_id = 5) both use john@example.com, so only the first occurrence of this email is retained.
+
+ +## Solutions + + + +### **Pandas** + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2883.Drop Missing Data/README.md b/solution/2800-2899/2883.Drop Missing Data/README.md new file mode 100644 index 0000000000000..de3d4cdcb3d98 --- /dev/null +++ b/solution/2800-2899/2883.Drop Missing Data/README.md @@ -0,0 +1,69 @@ +# [2883. Drop Missing Data](https://leetcode.cn/problems/drop-missing-data) + +[English Version](/solution/2800-2899/2883.Drop%20Missing%20Data/README_EN.md) + +## 题目描述 + + + +
+DataFrame students
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
++-------------+--------+
+
+ +

There are some rows having missing values in the name column.

+ +

Write a solution to remove the rows with missing values.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
++------------+-------+-----+
+| student_id | name  | age |
++------------+-------+-----+
+| 32         | Piper | 5   |
+| 217        | Grace | 19  |
+| 779        | None  | 20  |
+| 849        | None  | 14  |
++------------+-------+-----+
+Output:
++------------+-------+-----+
+| student_id | name  | age |
++------------+-------+-----+
+| 32         | Piper | 5   |
+| 217        | Grace | 19  |
++------------+-------+-----+
+Explanation: 
+Students with ids 779 and 849 have empty values in the name column, so they will be removed.
+ +## 解法 + + + + + +### **Pandas** + + + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2883.Drop Missing Data/README_EN.md b/solution/2800-2899/2883.Drop Missing Data/README_EN.md new file mode 100644 index 0000000000000..e734189c5c15a --- /dev/null +++ b/solution/2800-2899/2883.Drop Missing Data/README_EN.md @@ -0,0 +1,63 @@ +# [2883. Drop Missing Data](https://leetcode.com/problems/drop-missing-data) + +[中文文档](/solution/2800-2899/2883.Drop%20Missing%20Data/README.md) + +## Description + +
+DataFrame students
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
++-------------+--------+
+
+ +

There are some rows having missing values in the name column.

+ +

Write a solution to remove the rows with missing values.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
++------------+-------+-----+
+| student_id | name  | age |
++------------+-------+-----+
+| 32         | Piper | 5   |
+| 217        | Grace | 19  |
+| 779        | None  | 20  |
+| 849        | None  | 14  |
++------------+-------+-----+
+Output:
++------------+-------+-----+
+| student_id | name  | age |
++------------+-------+-----+
+| 32         | Piper | 5   |
+| 217        | Grace | 19  |
++------------+-------+-----+
+Explanation: 
+Students with ids 779 and 849 have empty values in the name column, so they will be removed.
+ +## Solutions + + + +### **Pandas** + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2884.Modify Columns/README.md b/solution/2800-2899/2884.Modify Columns/README.md new file mode 100644 index 0000000000000..d633476c32e14 --- /dev/null +++ b/solution/2800-2899/2884.Modify Columns/README.md @@ -0,0 +1,91 @@ +# [2884. Modify Columns](https://leetcode.cn/problems/modify-columns) + +[English Version](/solution/2800-2899/2884.Modify%20Columns/README_EN.md) + +## 题目描述 + + + +
+DataFrame employees
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| name        | object |
+| salary      | int    |
++-------------+--------+
+
+ +

A company intends to give its employees a pay rise.

+ +

Write a solution to modify the salary column by multiplying each salary by 2.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
+DataFrame employees
++---------+--------+
+| name    | salary |
++---------+--------+
+| Jack    | 19666  |
+| Piper   | 74754  |
+| Mia     | 62509  |
+| Ulysses | 54866  |
++---------+--------+
+Output:
++---------+--------+
+| name    | salary |
++---------+--------+
+| Jack    | 39332  |
+| Piper   | 149508 |
+| Mia     | 125018 |
+| Ulysses | 109732 |
++---------+--------+
+Explanation:
+Every salary has been doubled.
+ +## 解法 + + + + + +### **Python3** + + + +```python + +``` + +### **Java** + + + +```java + +``` + +### **C++** + +```cpp + +``` + +### **Go** + +```go + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2884.Modify Columns/README_EN.md b/solution/2800-2899/2884.Modify Columns/README_EN.md new file mode 100644 index 0000000000000..278754a8a286f --- /dev/null +++ b/solution/2800-2899/2884.Modify Columns/README_EN.md @@ -0,0 +1,65 @@ +# [2884. Modify Columns](https://leetcode.com/problems/modify-columns) + +[中文文档](/solution/2800-2899/2884.Modify%20Columns/README.md) + +## Description + +
+DataFrame employees
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| name        | object |
+| salary      | int    |
++-------------+--------+
+
+ +

A company intends to give its employees a pay rise.

+ +

Write a solution to modify the salary column by multiplying each salary by 2.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
+DataFrame employees
++---------+--------+
+| name    | salary |
++---------+--------+
+| Jack    | 19666  |
+| Piper   | 74754  |
+| Mia     | 62509  |
+| Ulysses | 54866  |
++---------+--------+
+Output:
++---------+--------+
+| name    | salary |
++---------+--------+
+| Jack    | 39332  |
+| Piper   | 149508 |
+| Mia     | 125018 |
+| Ulysses | 109732 |
++---------+--------+
+Explanation:
+Every salary has been doubled.
+ +## Solutions + + + +### **Pandas** + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2885.Rename Columns/README.md b/solution/2800-2899/2885.Rename Columns/README.md new file mode 100644 index 0000000000000..e777df88f3dfd --- /dev/null +++ b/solution/2800-2899/2885.Rename Columns/README.md @@ -0,0 +1,78 @@ +# [2885. Rename Columns](https://leetcode.cn/problems/rename-columns) + +[English Version](/solution/2800-2899/2885.Rename%20Columns/README_EN.md) + +## 题目描述 + + + +
+DataFrame students
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| id          | int    |
+| first       | object |
+| last        | object |
+| age         | int    |
++-------------+--------+
+
+ +

Write a solution to rename the columns as follows:

+ + + +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:
++----+---------+----------+-----+
+| id | first   | last     | age |
++----+---------+----------+-----+
+| 1  | Mason   | King     | 6   |
+| 2  | Ava     | Wright   | 7   |
+| 3  | Taylor  | Hall     | 16  |
+| 4  | Georgia | Thompson | 18  |
+| 5  | Thomas  | Moore    | 10  |
++----+---------+----------+-----+
+Output:
++------------+------------+-----------+--------------+
+| student_id | first_name | last_name | age_in_years |
++------------+------------+-----------+--------------+
+| 1          | Mason      | King      | 6            |
+| 2          | Ava        | Wright    | 7            |
+| 3          | Taylor     | Hall      | 16           |
+| 4          | Georgia    | Thompson  | 18           |
+| 5          | Thomas     | Moore     | 10           |
++------------+------------+-----------+--------------+
+Explanation: 
+The column names are changed accordingly.
+ +## 解法 + + + + + +### **Pandas** + + + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2885.Rename Columns/README_EN.md b/solution/2800-2899/2885.Rename Columns/README_EN.md new file mode 100644 index 0000000000000..92ebae4c996fa --- /dev/null +++ b/solution/2800-2899/2885.Rename Columns/README_EN.md @@ -0,0 +1,72 @@ +# [2885. Rename Columns](https://leetcode.com/problems/rename-columns) + +[中文文档](/solution/2800-2899/2885.Rename%20Columns/README.md) + +## Description + +
+DataFrame students
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| id          | int    |
+| first       | object |
+| last        | object |
+| age         | int    |
++-------------+--------+
+
+ +

Write a solution to rename the columns as follows:

+ + + +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:
++----+---------+----------+-----+
+| id | first   | last     | age |
++----+---------+----------+-----+
+| 1  | Mason   | King     | 6   |
+| 2  | Ava     | Wright   | 7   |
+| 3  | Taylor  | Hall     | 16  |
+| 4  | Georgia | Thompson | 18  |
+| 5  | Thomas  | Moore    | 10  |
++----+---------+----------+-----+
+Output:
++------------+------------+-----------+--------------+
+| student_id | first_name | last_name | age_in_years |
++------------+------------+-----------+--------------+
+| 1          | Mason      | King      | 6            |
+| 2          | Ava        | Wright    | 7            |
+| 3          | Taylor     | Hall      | 16           |
+| 4          | Georgia    | Thompson  | 18           |
+| 5          | Thomas     | Moore     | 10           |
++------------+------------+-----------+--------------+
+Explanation: 
+The column names are changed accordingly.
+ +## Solutions + + + +### **Pandas** + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2886.Change Data Type/README.md b/solution/2800-2899/2886.Change Data Type/README.md new file mode 100644 index 0000000000000..9e4c1d45674d0 --- /dev/null +++ b/solution/2800-2899/2886.Change Data Type/README.md @@ -0,0 +1,68 @@ +# [2886. Change Data Type](https://leetcode.cn/problems/change-data-type) + +[English Version](/solution/2800-2899/2886.Change%20Data%20Type/README_EN.md) + +## 题目描述 + + + +
+DataFrame students
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
+| grade       | float  |
++-------------+--------+
+
+ +

Write a solution to correct the errors:

+ +

The grade column is stored as floats, convert it to integers.

+ +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:
+DataFrame students:
++------------+------+-----+-------+
+| student_id | name | age | grade |
++------------+------+-----+-------+
+| 1          | Ava  | 6   | 73.0  |
+| 2          | Kate | 15  | 87.0  |
++------------+------+-----+-------+
+Output:
++------------+------+-----+-------+
+| student_id | name | age | grade |
++------------+------+-----+-------+
+| 1          | Ava  | 6   | 73    |
+| 2          | Kate | 15  | 87    |
++------------+------+-----+-------+
+Explanation: 
+The data types of the column grade is converted to int.
+ +## 解法 + + + + + +### **Pandas** + + + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2886.Change Data Type/README_EN.md b/solution/2800-2899/2886.Change Data Type/README_EN.md new file mode 100644 index 0000000000000..9621d8d7644e3 --- /dev/null +++ b/solution/2800-2899/2886.Change Data Type/README_EN.md @@ -0,0 +1,62 @@ +# [2886. Change Data Type](https://leetcode.com/problems/change-data-type) + +[中文文档](/solution/2800-2899/2886.Change%20Data%20Type/README.md) + +## Description + +
+DataFrame students
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
+| grade       | float  |
++-------------+--------+
+
+ +

Write a solution to correct the errors:

+ +

The grade column is stored as floats, convert it to integers.

+ +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:
+DataFrame students:
++------------+------+-----+-------+
+| student_id | name | age | grade |
++------------+------+-----+-------+
+| 1          | Ava  | 6   | 73.0  |
+| 2          | Kate | 15  | 87.0  |
++------------+------+-----+-------+
+Output:
++------------+------+-----+-------+
+| student_id | name | age | grade |
++------------+------+-----+-------+
+| 1          | Ava  | 6   | 73    |
+| 2          | Kate | 15  | 87    |
++------------+------+-----+-------+
+Explanation: 
+The data types of the column grade is converted to int.
+ +## Solutions + + + +### **Pandas** + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2887.Fill Missing Data/README.md b/solution/2800-2899/2887.Fill Missing Data/README.md new file mode 100644 index 0000000000000..58f95f6f701f1 --- /dev/null +++ b/solution/2800-2899/2887.Fill Missing Data/README.md @@ -0,0 +1,67 @@ +# [2887. Fill Missing Data](https://leetcode.cn/problems/fill-missing-data) + +[English Version](/solution/2800-2899/2887.Fill%20Missing%20Data/README_EN.md) + +## 题目描述 + + + +
+DataFrame products
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| name        | object |
+| quantity    | int    |
+| price       | int    |
++-------------+--------+
+
+ +

Write a solution to fill in the missing value as 0 in the quantity column.

+ +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:+-----------------+----------+-------+
+| name            | quantity | price |
++-----------------+----------+-------+
+| Wristwatch      | 32       | 135   |
+| WirelessEarbuds | None     | 821   |
+| GolfClubs       | None     | 9319  |
+| Printer         | 849      | 3051  |
++-----------------+----------+-------+
+Output:
++-----------------+----------+-------+
+| name            | quantity | price |
++-----------------+----------+-------+
+| Wristwatch      | 32       | 135   |
+| WirelessEarbuds | 0        | 821   |
+| GolfClubs       | 0        | 9319  |
+| Printer         | 849      | 3051  |
++-----------------+----------+-------+
+Explanation: 
+The quantity for Toaster and Headphones are filled by 0.
+ +## 解法 + + + + + +### **Pandas** + + + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2887.Fill Missing Data/README_EN.md b/solution/2800-2899/2887.Fill Missing Data/README_EN.md new file mode 100644 index 0000000000000..457f309e21001 --- /dev/null +++ b/solution/2800-2899/2887.Fill Missing Data/README_EN.md @@ -0,0 +1,61 @@ +# [2887. Fill Missing Data](https://leetcode.com/problems/fill-missing-data) + +[中文文档](/solution/2800-2899/2887.Fill%20Missing%20Data/README.md) + +## Description + +
+DataFrame products
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| name        | object |
+| quantity    | int    |
+| price       | int    |
++-------------+--------+
+
+ +

Write a solution to fill in the missing value as 0 in the quantity column.

+ +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:+-----------------+----------+-------+
+| name            | quantity | price |
++-----------------+----------+-------+
+| Wristwatch      | 32       | 135   |
+| WirelessEarbuds | None     | 821   |
+| GolfClubs       | None     | 9319  |
+| Printer         | 849      | 3051  |
++-----------------+----------+-------+
+Output:
++-----------------+----------+-------+
+| name            | quantity | price |
++-----------------+----------+-------+
+| Wristwatch      | 32       | 135   |
+| WirelessEarbuds | 0        | 821   |
+| GolfClubs       | 0        | 9319  |
+| Printer         | 849      | 3051  |
++-----------------+----------+-------+
+Explanation: 
+The quantity for Toaster and Headphones are filled by 0.
+ +## Solutions + + + +### **Pandas** + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2888.Reshape Data Concatenate/README.md b/solution/2800-2899/2888.Reshape Data Concatenate/README.md new file mode 100644 index 0000000000000..4f6d641c08d9d --- /dev/null +++ b/solution/2800-2899/2888.Reshape Data Concatenate/README.md @@ -0,0 +1,89 @@ +# [2888. Reshape Data Concatenate](https://leetcode.cn/problems/reshape-data-concatenate) + +[English Version](/solution/2800-2899/2888.Reshape%20Data%20Concatenate/README_EN.md) + +## 题目描述 + + + +
+DataFrame df1
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
++-------------+--------+
+
+DataFrame df2
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
++-------------+--------+
+
+
+ +

Write a solution to concatenate these two DataFrames vertically into one DataFrame.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
+df1
++------------+---------+-----+
+| student_id | name    | age |
++------------+---------+-----+
+| 1          | Mason   | 8   |
+| 2          | Ava     | 6   |
+| 3          | Taylor  | 15  |
+| 4          | Georgia | 17  |
++------------+---------+-----+
+df2
++------------+------+-----+
+| student_id | name | age |
++------------+------+-----+
+| 5          | Leo  | 7   |
+| 6          | Alex | 7   |
++------------+------+-----+
+Output:
++------------+---------+-----+
+| student_id | name    | age |
++------------+---------+-----+
+| 1          | Mason   | 8   |
+| 2          | Ava     | 6   |
+| 3          | Taylor  | 15  |
+| 4          | Georgia | 17  |
+| 5          | Leo     | 7   |
+| 6          | Alex    | 7   |
++------------+---------+-----+
+Explanation:
+The two DataFramess are stacked vertically, and their rows are combined.
+ +## 解法 + + + + + +### **Pandas** + + + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2888.Reshape Data Concatenate/README_EN.md b/solution/2800-2899/2888.Reshape Data Concatenate/README_EN.md new file mode 100644 index 0000000000000..adfd7224f73c0 --- /dev/null +++ b/solution/2800-2899/2888.Reshape Data Concatenate/README_EN.md @@ -0,0 +1,83 @@ +# [2888. Reshape Data Concatenate](https://leetcode.com/problems/reshape-data-concatenate) + +[中文文档](/solution/2800-2899/2888.Reshape%20Data%20Concatenate/README.md) + +## Description + +
+DataFrame df1
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
++-------------+--------+
+
+DataFrame df2
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| student_id  | int    |
+| name        | object |
+| age         | int    |
++-------------+--------+
+
+
+ +

Write a solution to concatenate these two DataFrames vertically into one DataFrame.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
+df1
++------------+---------+-----+
+| student_id | name    | age |
++------------+---------+-----+
+| 1          | Mason   | 8   |
+| 2          | Ava     | 6   |
+| 3          | Taylor  | 15  |
+| 4          | Georgia | 17  |
++------------+---------+-----+
+df2
++------------+------+-----+
+| student_id | name | age |
++------------+------+-----+
+| 5          | Leo  | 7   |
+| 6          | Alex | 7   |
++------------+------+-----+
+Output:
++------------+---------+-----+
+| student_id | name    | age |
++------------+---------+-----+
+| 1          | Mason   | 8   |
+| 2          | Ava     | 6   |
+| 3          | Taylor  | 15  |
+| 4          | Georgia | 17  |
+| 5          | Leo     | 7   |
+| 6          | Alex    | 7   |
++------------+---------+-----+
+Explanation:
+The two DataFramess are stacked vertically, and their rows are combined.
+ +## Solutions + + + +### **Pandas** + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2889.Reshape Data Pivot/README.md b/solution/2800-2899/2889.Reshape Data Pivot/README.md new file mode 100644 index 0000000000000..3878d857387db --- /dev/null +++ b/solution/2800-2899/2889.Reshape Data Pivot/README.md @@ -0,0 +1,75 @@ +# [2889. Reshape Data Pivot](https://leetcode.cn/problems/reshape-data-pivot) + +[English Version](/solution/2800-2899/2889.Reshape%20Data%20Pivot/README_EN.md) + +## 题目描述 + + + +
+DataFrame weather
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| city        | object |
+| month       | object |
+| temperature | int    |
++-------------+--------+
+
+ +

Write a solution to pivot the data so that each row represents temperatures for a specific month, and each city is a separate column.

+ +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:
++--------------+----------+-------------+
+| city         | month    | temperature |
++--------------+----------+-------------+
+| Jacksonville | January  | 13          |
+| Jacksonville | February | 23          |
+| Jacksonville | March    | 38          |
+| Jacksonville | April    | 5           |
+| Jacksonville | May      | 34          |
+| ElPaso       | January  | 20          |
+| ElPaso       | February | 6           |
+| ElPaso       | March    | 26          |
+| ElPaso       | April    | 2           |
+| ElPaso       | May      | 43          |
++--------------+----------+-------------+
+Output:
++----------+--------+--------------+
+| month    | ElPaso | Jacksonville |
++----------+--------+--------------+
+| April    | 2      | 5            |
+| February | 6      | 23           |
+| January  | 20     | 13           |
+| March    | 26     | 38           |
+| May      | 43     | 34           |
++----------+--------+--------------+
+Explanation:
+The table is pivoted, each column represents a city, and each row represents a specific month.
+ +## 解法 + + + + + +### **Pandas** + + + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2889.Reshape Data Pivot/README_EN.md b/solution/2800-2899/2889.Reshape Data Pivot/README_EN.md new file mode 100644 index 0000000000000..591a56358e875 --- /dev/null +++ b/solution/2800-2899/2889.Reshape Data Pivot/README_EN.md @@ -0,0 +1,69 @@ +# [2889. Reshape Data Pivot](https://leetcode.com/problems/reshape-data-pivot) + +[中文文档](/solution/2800-2899/2889.Reshape%20Data%20Pivot/README.md) + +## Description + +
+DataFrame weather
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| city        | object |
+| month       | object |
+| temperature | int    |
++-------------+--------+
+
+ +

Write a solution to pivot the data so that each row represents temperatures for a specific month, and each city is a separate column.

+ +

The result format is in the following example.

+ +

 

+
+Example 1:
+Input:
++--------------+----------+-------------+
+| city         | month    | temperature |
++--------------+----------+-------------+
+| Jacksonville | January  | 13          |
+| Jacksonville | February | 23          |
+| Jacksonville | March    | 38          |
+| Jacksonville | April    | 5           |
+| Jacksonville | May      | 34          |
+| ElPaso       | January  | 20          |
+| ElPaso       | February | 6           |
+| ElPaso       | March    | 26          |
+| ElPaso       | April    | 2           |
+| ElPaso       | May      | 43          |
++--------------+----------+-------------+
+Output:
++----------+--------+--------------+
+| month    | ElPaso | Jacksonville |
++----------+--------+--------------+
+| April    | 2      | 5            |
+| February | 6      | 23           |
+| January  | 20     | 13           |
+| March    | 26     | 38           |
+| May      | 43     | 34           |
++----------+--------+--------------+
+Explanation:
+The table is pivoted, each column represents a city, and each row represents a specific month.
+ +## Solutions + + + +### **Pandas** + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2890.Reshape Data Melt/README.md b/solution/2800-2899/2890.Reshape Data Melt/README.md new file mode 100644 index 0000000000000..ac53e67a31790 --- /dev/null +++ b/solution/2800-2899/2890.Reshape Data Melt/README.md @@ -0,0 +1,74 @@ +# [2890. Reshape Data Melt](https://leetcode.cn/problems/reshape-data-melt) + +[English Version](/solution/2800-2899/2890.Reshape%20Data%20Melt/README_EN.md) + +## 题目描述 + + + +
+DataFrame report
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| product     | object |
+| quarter_1   | int    |
+| quarter_2   | int    |
+| quarter_3   | int    |
+| quarter_4   | int    |
++-------------+--------+
+
+ +

Write a solution to reshape the data so that each row represents sales data for a product in a specific quarter.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
++-------------+-----------+-----------+-----------+-----------+
+| product     | quarter_1 | quarter_2 | quarter_3 | quarter_4 |
++-------------+-----------+-----------+-----------+-----------+
+| Umbrella    | 417       | 224       | 379       | 611       |
+| SleepingBag | 800       | 936       | 93        | 875       |
++-------------+-----------+-----------+-----------+-----------+
+Output:
++-------------+-----------+-------+
+| product     | quarter   | sales |
++-------------+-----------+-------+
+| Umbrella    | quarter_1 | 417   |
+| SleepingBag | quarter_1 | 800   |
+| Umbrella    | quarter_2 | 224   |
+| SleepingBag | quarter_2 | 936   |
+| Umbrella    | quarter_3 | 379   |
+| SleepingBag | quarter_3 | 93    |
+| Umbrella    | quarter_4 | 611   |
+| SleepingBag | quarter_4 | 875   |
++-------------+-----------+-------+
+Explanation:
+The DataFrame is reshaped from wide to long format. Each row represents the sales of a product in a quarter.
+
+ +## 解法 + + + + + +### **Pandas** + + + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2890.Reshape Data Melt/README_EN.md b/solution/2800-2899/2890.Reshape Data Melt/README_EN.md new file mode 100644 index 0000000000000..ab02354a5928f --- /dev/null +++ b/solution/2800-2899/2890.Reshape Data Melt/README_EN.md @@ -0,0 +1,68 @@ +# [2890. Reshape Data Melt](https://leetcode.com/problems/reshape-data-melt) + +[中文文档](/solution/2800-2899/2890.Reshape%20Data%20Melt/README.md) + +## Description + +
+DataFrame report
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| product     | object |
+| quarter_1   | int    |
+| quarter_2   | int    |
+| quarter_3   | int    |
+| quarter_4   | int    |
++-------------+--------+
+
+ +

Write a solution to reshape the data so that each row represents sales data for a product in a specific quarter.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input:
++-------------+-----------+-----------+-----------+-----------+
+| product     | quarter_1 | quarter_2 | quarter_3 | quarter_4 |
++-------------+-----------+-----------+-----------+-----------+
+| Umbrella    | 417       | 224       | 379       | 611       |
+| SleepingBag | 800       | 936       | 93        | 875       |
++-------------+-----------+-----------+-----------+-----------+
+Output:
++-------------+-----------+-------+
+| product     | quarter   | sales |
++-------------+-----------+-------+
+| Umbrella    | quarter_1 | 417   |
+| SleepingBag | quarter_1 | 800   |
+| Umbrella    | quarter_2 | 224   |
+| SleepingBag | quarter_2 | 936   |
+| Umbrella    | quarter_3 | 379   |
+| SleepingBag | quarter_3 | 93    |
+| Umbrella    | quarter_4 | 611   |
+| SleepingBag | quarter_4 | 875   |
++-------------+-----------+-------+
+Explanation:
+The DataFrame is reshaped from wide to long format. Each row represents the sales of a product in a quarter.
+
+ +## Solutions + + + +### **Pandas** + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2891.Method Chaining/README.md b/solution/2800-2899/2891.Method Chaining/README.md new file mode 100644 index 0000000000000..063d561bbab77 --- /dev/null +++ b/solution/2800-2899/2891.Method Chaining/README.md @@ -0,0 +1,82 @@ +# [2891. Method Chaining](https://leetcode.cn/problems/method-chaining) + +[English Version](/solution/2800-2899/2891.Method%20Chaining/README_EN.md) + +## 题目描述 + + + +
+DataFrame animals
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| name        | object |
+| species     | object |
+| age         | int    |
+| weight      | int    |
++-------------+--------+
+
+ +

Write a solution to list the names of animals that weigh strictly more than 100 kilograms.

+ +

Return the animals sorted by weight in descending order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+DataFrame animals:
++----------+---------+-----+--------+
+| name     | species | age | weight |
++----------+---------+-----+--------+
+| Tatiana  | Snake   | 98  | 464    |
+| Khaled   | Giraffe | 50  | 41     |
+| Alex     | Leopard | 6   | 328    |
+| Jonathan | Monkey  | 45  | 463    |
+| Stefan   | Bear    | 100 | 50     |
+| Tommy    | Panda   | 26  | 349    |
++----------+---------+-----+--------+
+Output: 
++----------+
+| name     |
++----------+
+| Tatiana  |
+| Jonathan |
+| Tommy    |
+| Alex     |
++----------+
+Explanation: 
+All animals weighing more than 100 should be included in the results table.
+Tatiana's weight is 464, Jonathan's weight is 463, Tommy's weight is 349, and Alex's weight is 328.
+The results should be sorted in descending order of weight.
+ +

 

+

In Pandas, method chaining enables us to perform operations on a DataFrame without breaking up each operation into a separate line or creating multiple temporary variables. 

+ +

Can you complete this task in just one line of code using method chaining?

+ +## 解法 + + + + + +### **Pandas** + + + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/2800-2899/2891.Method Chaining/README_EN.md b/solution/2800-2899/2891.Method Chaining/README_EN.md new file mode 100644 index 0000000000000..9dc7181aae179 --- /dev/null +++ b/solution/2800-2899/2891.Method Chaining/README_EN.md @@ -0,0 +1,76 @@ +# [2891. Method Chaining](https://leetcode.com/problems/method-chaining) + +[中文文档](/solution/2800-2899/2891.Method%20Chaining/README.md) + +## Description + +
+DataFrame animals
++-------------+--------+
+| Column Name | Type   |
++-------------+--------+
+| name        | object |
+| species     | object |
+| age         | int    |
+| weight      | int    |
++-------------+--------+
+
+ +

Write a solution to list the names of animals that weigh strictly more than 100 kilograms.

+ +

Return the animals sorted by weight in descending order.

+ +

The result format is in the following example.

+ +

 

+

Example 1:

+ +
+Input: 
+DataFrame animals:
++----------+---------+-----+--------+
+| name     | species | age | weight |
++----------+---------+-----+--------+
+| Tatiana  | Snake   | 98  | 464    |
+| Khaled   | Giraffe | 50  | 41     |
+| Alex     | Leopard | 6   | 328    |
+| Jonathan | Monkey  | 45  | 463    |
+| Stefan   | Bear    | 100 | 50     |
+| Tommy    | Panda   | 26  | 349    |
++----------+---------+-----+--------+
+Output: 
++----------+
+| name     |
++----------+
+| Tatiana  |
+| Jonathan |
+| Tommy    |
+| Alex     |
++----------+
+Explanation: 
+All animals weighing more than 100 should be included in the results table.
+Tatiana's weight is 464, Jonathan's weight is 463, Tommy's weight is 349, and Alex's weight is 328.
+The results should be sorted in descending order of weight.
+ +

 

+

In Pandas, method chaining enables us to perform operations on a DataFrame without breaking up each operation into a separate line or creating multiple temporary variables. 

+ +

Can you complete this task in just one line of code using method chaining?

+ +## Solutions + + + +### **Pandas** + +```python + +``` + +### **...** + +``` + +``` + + diff --git a/solution/README.md b/solution/README.md index 8ed7fec1e0434..135c4a5f18f26 100644 --- a/solution/README.md +++ b/solution/README.md @@ -2887,6 +2887,21 @@ | 2874 | [有序三元组中的最大值 II](/solution/2800-2899/2874.Maximum%20Value%20of%20an%20Ordered%20Triplet%20II/README.md) | | 中等 | 第 365 场周赛 | | 2875 | [无限数组的最短子数组](/solution/2800-2899/2875.Minimum%20Size%20Subarray%20in%20Infinite%20Array/README.md) | | 中等 | 第 365 场周赛 | | 2876 | [有向图访问计数](/solution/2800-2899/2876.Count%20Visited%20Nodes%20in%20a%20Directed%20Graph/README.md) | | 困难 | 第 365 场周赛 | +| 2877 | [Create a DataFrame from List](/solution/2800-2899/2877.Create%20a%20DataFrame%20from%20List/README.md) | | 简单 | | +| 2878 | [Get the Size of a DataFrame](/solution/2800-2899/2878.Get%20the%20Size%20of%20a%20DataFrame/README.md) | | 简单 | | +| 2879 | [Display the First Three Rows](/solution/2800-2899/2879.Display%20the%20First%20Three%20Rows/README.md) | | 简单 | | +| 2880 | [Select Data](/solution/2800-2899/2880.Select%20Data/README.md) | | 简单 | | +| 2881 | [Create a New Column](/solution/2800-2899/2881.Create%20a%20New%20Column/README.md) | | 简单 | | +| 2882 | [Drop Duplicate Rows](/solution/2800-2899/2882.Drop%20Duplicate%20Rows/README.md) | | 简单 | | +| 2883 | [Drop Missing Data](/solution/2800-2899/2883.Drop%20Missing%20Data/README.md) | | 简单 | | +| 2884 | [Modify Columns](/solution/2800-2899/2884.Modify%20Columns/README.md) | | 简单 | | +| 2885 | [Rename Columns](/solution/2800-2899/2885.Rename%20Columns/README.md) | | 简单 | | +| 2886 | [Change Data Type](/solution/2800-2899/2886.Change%20Data%20Type/README.md) | | 简单 | | +| 2887 | [Fill Missing Data](/solution/2800-2899/2887.Fill%20Missing%20Data/README.md) | | 简单 | | +| 2888 | [Reshape Data Concatenate](/solution/2800-2899/2888.Reshape%20Data%20Concatenate/README.md) | | 简单 | | +| 2889 | [Reshape Data Pivot](/solution/2800-2899/2889.Reshape%20Data%20Pivot/README.md) | | 简单 | | +| 2890 | [Reshape Data Melt](/solution/2800-2899/2890.Reshape%20Data%20Melt/README.md) | | 简单 | | +| 2891 | [Method Chaining](/solution/2800-2899/2891.Method%20Chaining/README.md) | | 简单 | | ## 版权 diff --git a/solution/README_EN.md b/solution/README_EN.md index 74263b51eaf68..d1697a98cc22e 100644 --- a/solution/README_EN.md +++ b/solution/README_EN.md @@ -2885,6 +2885,21 @@ Press Control + F(or Command + F on | 2874 | [Maximum Value of an Ordered Triplet II](/solution/2800-2899/2874.Maximum%20Value%20of%20an%20Ordered%20Triplet%20II/README_EN.md) | | Medium | Weekly Contest 365 | | 2875 | [Minimum Size Subarray in Infinite Array](/solution/2800-2899/2875.Minimum%20Size%20Subarray%20in%20Infinite%20Array/README_EN.md) | | Medium | Weekly Contest 365 | | 2876 | [Count Visited Nodes in a Directed Graph](/solution/2800-2899/2876.Count%20Visited%20Nodes%20in%20a%20Directed%20Graph/README_EN.md) | | Hard | Weekly Contest 365 | +| 2877 | [Create a DataFrame from List](/solution/2800-2899/2877.Create%20a%20DataFrame%20from%20List/README_EN.md) | | Easy | | +| 2878 | [Get the Size of a DataFrame](/solution/2800-2899/2878.Get%20the%20Size%20of%20a%20DataFrame/README_EN.md) | | Easy | | +| 2879 | [Display the First Three Rows](/solution/2800-2899/2879.Display%20the%20First%20Three%20Rows/README_EN.md) | | Easy | | +| 2880 | [Select Data](/solution/2800-2899/2880.Select%20Data/README_EN.md) | | Easy | | +| 2881 | [Create a New Column](/solution/2800-2899/2881.Create%20a%20New%20Column/README_EN.md) | | Easy | | +| 2882 | [Drop Duplicate Rows](/solution/2800-2899/2882.Drop%20Duplicate%20Rows/README_EN.md) | | Easy | | +| 2883 | [Drop Missing Data](/solution/2800-2899/2883.Drop%20Missing%20Data/README_EN.md) | | Easy | | +| 2884 | [Modify Columns](/solution/2800-2899/2884.Modify%20Columns/README_EN.md) | | Easy | | +| 2885 | [Rename Columns](/solution/2800-2899/2885.Rename%20Columns/README_EN.md) | | Easy | | +| 2886 | [Change Data Type](/solution/2800-2899/2886.Change%20Data%20Type/README_EN.md) | | Easy | | +| 2887 | [Fill Missing Data](/solution/2800-2899/2887.Fill%20Missing%20Data/README_EN.md) | | Easy | | +| 2888 | [Reshape Data Concatenate](/solution/2800-2899/2888.Reshape%20Data%20Concatenate/README_EN.md) | | Easy | | +| 2889 | [Reshape Data Pivot](/solution/2800-2899/2889.Reshape%20Data%20Pivot/README_EN.md) | | Easy | | +| 2890 | [Reshape Data Melt](/solution/2800-2899/2890.Reshape%20Data%20Melt/README_EN.md) | | Easy | | +| 2891 | [Method Chaining](/solution/2800-2899/2891.Method%20Chaining/README_EN.md) | | Easy | | ## Copyright diff --git a/solution/summary.md b/solution/summary.md index 54ba4afbca9de..5e74965c18e75 100644 --- a/solution/summary.md +++ b/solution/summary.md @@ -2932,3 +2932,18 @@ - [2874.有序三元组中的最大值 II](/solution/2800-2899/2874.Maximum%20Value%20of%20an%20Ordered%20Triplet%20II/README.md) - [2875.无限数组的最短子数组](/solution/2800-2899/2875.Minimum%20Size%20Subarray%20in%20Infinite%20Array/README.md) - [2876.有向图访问计数](/solution/2800-2899/2876.Count%20Visited%20Nodes%20in%20a%20Directed%20Graph/README.md) + - [2877.Create a DataFrame from List](/solution/2800-2899/2877.Create%20a%20DataFrame%20from%20List/README.md) + - [2878.Get the Size of a DataFrame](/solution/2800-2899/2878.Get%20the%20Size%20of%20a%20DataFrame/README.md) + - [2879.Display the First Three Rows](/solution/2800-2899/2879.Display%20the%20First%20Three%20Rows/README.md) + - [2880.Select Data](/solution/2800-2899/2880.Select%20Data/README.md) + - [2881.Create a New Column](/solution/2800-2899/2881.Create%20a%20New%20Column/README.md) + - [2882.Drop Duplicate Rows](/solution/2800-2899/2882.Drop%20Duplicate%20Rows/README.md) + - [2883.Drop Missing Data](/solution/2800-2899/2883.Drop%20Missing%20Data/README.md) + - [2884.Modify Columns](/solution/2800-2899/2884.Modify%20Columns/README.md) + - [2885.Rename Columns](/solution/2800-2899/2885.Rename%20Columns/README.md) + - [2886.Change Data Type](/solution/2800-2899/2886.Change%20Data%20Type/README.md) + - [2887.Fill Missing Data](/solution/2800-2899/2887.Fill%20Missing%20Data/README.md) + - [2888.Reshape Data Concatenate](/solution/2800-2899/2888.Reshape%20Data%20Concatenate/README.md) + - [2889.Reshape Data Pivot](/solution/2800-2899/2889.Reshape%20Data%20Pivot/README.md) + - [2890.Reshape Data Melt](/solution/2800-2899/2890.Reshape%20Data%20Melt/README.md) + - [2891.Method Chaining](/solution/2800-2899/2891.Method%20Chaining/README.md) diff --git a/solution/summary_en.md b/solution/summary_en.md index bc64d788689a8..a5d9abfd7daf8 100644 --- a/solution/summary_en.md +++ b/solution/summary_en.md @@ -2932,3 +2932,18 @@ - [2874.Maximum Value of an Ordered Triplet II](/solution/2800-2899/2874.Maximum%20Value%20of%20an%20Ordered%20Triplet%20II/README_EN.md) - [2875.Minimum Size Subarray in Infinite Array](/solution/2800-2899/2875.Minimum%20Size%20Subarray%20in%20Infinite%20Array/README_EN.md) - [2876.Count Visited Nodes in a Directed Graph](/solution/2800-2899/2876.Count%20Visited%20Nodes%20in%20a%20Directed%20Graph/README_EN.md) + - [2877.Create a DataFrame from List](/solution/2800-2899/2877.Create%20a%20DataFrame%20from%20List/README_EN.md) + - [2878.Get the Size of a DataFrame](/solution/2800-2899/2878.Get%20the%20Size%20of%20a%20DataFrame/README_EN.md) + - [2879.Display the First Three Rows](/solution/2800-2899/2879.Display%20the%20First%20Three%20Rows/README_EN.md) + - [2880.Select Data](/solution/2800-2899/2880.Select%20Data/README_EN.md) + - [2881.Create a New Column](/solution/2800-2899/2881.Create%20a%20New%20Column/README_EN.md) + - [2882.Drop Duplicate Rows](/solution/2800-2899/2882.Drop%20Duplicate%20Rows/README_EN.md) + - [2883.Drop Missing Data](/solution/2800-2899/2883.Drop%20Missing%20Data/README_EN.md) + - [2884.Modify Columns](/solution/2800-2899/2884.Modify%20Columns/README_EN.md) + - [2885.Rename Columns](/solution/2800-2899/2885.Rename%20Columns/README_EN.md) + - [2886.Change Data Type](/solution/2800-2899/2886.Change%20Data%20Type/README_EN.md) + - [2887.Fill Missing Data](/solution/2800-2899/2887.Fill%20Missing%20Data/README_EN.md) + - [2888.Reshape Data Concatenate](/solution/2800-2899/2888.Reshape%20Data%20Concatenate/README_EN.md) + - [2889.Reshape Data Pivot](/solution/2800-2899/2889.Reshape%20Data%20Pivot/README_EN.md) + - [2890.Reshape Data Melt](/solution/2800-2899/2890.Reshape%20Data%20Melt/README_EN.md) + - [2891.Method Chaining](/solution/2800-2899/2891.Method%20Chaining/README_EN.md)