Skip to content

Commit 99c4667

Browse files
authored
chore: add new lc problems (doocs#1749)
1 parent 96724fc commit 99c4667

File tree

34 files changed

+2196
-0
lines changed

34 files changed

+2196
-0
lines changed
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# [2877. Create a DataFrame from List](https://leetcode.cn/problems/create-a-dataframe-from-list)
2+
3+
[English Version](/solution/2800-2899/2877.Create%20a%20DataFrame%20from%20List/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>Write a solution to <strong>create</strong> a DataFrame from a 2D list called <code>student_data</code>. This 2D list contains the IDs and ages of some students.</p>
10+
11+
<p>The DataFrame should have two columns, <code>student_id</code> and <code>age</code>, and be in the same order as the original 2D list.</p>
12+
13+
<p>The result format is in the following example.</p>
14+
15+
<p>&nbsp;</p>
16+
<p><strong class="example">Example 1:</strong></p>
17+
18+
<pre>
19+
<strong>Input:
20+
</strong>student_data:<strong>
21+
</strong><code>[
22+
[1, 15],
23+
[2, 11],
24+
[3, 11],
25+
[4, 20]
26+
]</code>
27+
<strong>Output:</strong>
28+
+------------+-----+
29+
| student_id | age |
30+
+------------+-----+
31+
| 1 | 15 |
32+
| 2 | 11 |
33+
| 3 | 11 |
34+
| 4 | 20 |
35+
+------------+-----+
36+
<strong>Explanation:</strong>
37+
A DataFrame was created on top of student_data, with two columns named <code>student_id</code> and <code>age</code>.
38+
</pre>
39+
40+
## 解法
41+
42+
<!-- 这里可写通用的实现逻辑 -->
43+
44+
<!-- tabs:start -->
45+
46+
### **Pandas**
47+
48+
<!-- 这里可写当前语言的特殊实现逻辑 -->
49+
50+
```python
51+
52+
```
53+
54+
### **...**
55+
56+
```
57+
58+
```
59+
60+
<!-- tabs:end -->
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# [2877. Create a DataFrame from List](https://leetcode.com/problems/create-a-dataframe-from-list)
2+
3+
[中文文档](/solution/2800-2899/2877.Create%20a%20DataFrame%20from%20List/README.md)
4+
5+
## Description
6+
7+
<p>Write a solution to <strong>create</strong> a DataFrame from a 2D list called <code>student_data</code>. This 2D list contains the IDs and ages of some students.</p>
8+
9+
<p>The DataFrame should have two columns, <code>student_id</code> and <code>age</code>, and be in the same order as the original 2D list.</p>
10+
11+
<p>The result format is in the following example.</p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong class="example">Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:
18+
</strong>student_data:<strong>
19+
</strong><code>[
20+
[1, 15],
21+
[2, 11],
22+
[3, 11],
23+
[4, 20]
24+
]</code>
25+
<strong>Output:</strong>
26+
+------------+-----+
27+
| student_id | age |
28+
+------------+-----+
29+
| 1 | 15 |
30+
| 2 | 11 |
31+
| 3 | 11 |
32+
| 4 | 20 |
33+
+------------+-----+
34+
<strong>Explanation:</strong>
35+
A DataFrame was created on top of student_data, with two columns named <code>student_id</code> and <code>age</code>.
36+
</pre>
37+
38+
## Solutions
39+
40+
<!-- tabs:start -->
41+
42+
### **Pandas**
43+
44+
```python
45+
46+
```
47+
48+
### **...**
49+
50+
```
51+
52+
```
53+
54+
<!-- tabs:end -->
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# [2878. Get the Size of a DataFrame](https://leetcode.cn/problems/get-the-size-of-a-dataframe)
2+
3+
[English Version](/solution/2800-2899/2878.Get%20the%20Size%20of%20a%20DataFrame/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<pre>
10+
DataFrame <code>players:</code>
11+
+-------------+--------+
12+
| Column Name | Type |
13+
+-------------+--------+
14+
| player_id | int |
15+
| name | object |
16+
| age | int |
17+
| position | object |
18+
| ... | ... |
19+
+-------------+--------+
20+
</pre>
21+
22+
<p>Write a solution to calculate and display the <strong>number of rows and columns</strong> of <code>players</code>.</p>
23+
24+
<p>Return the result as an array:</p>
25+
26+
<p><code>[number of rows, number of columns]</code></p>
27+
28+
<p>The result format is in the following example.</p>
29+
30+
<p>&nbsp;</p>
31+
<p><strong class="example">Example 1:</strong></p>
32+
33+
<pre>
34+
<strong>Input:
35+
</strong>+-----------+----------+-----+-------------+--------------------+
36+
| player_id | name | age | position | team |
37+
+-----------+----------+-----+-------------+--------------------+
38+
| 846 | Mason | 21 | Forward | RealMadrid |
39+
| 749 | Riley | 30 | Winger | Barcelona |
40+
| 155 | Bob | 28 | Striker | ManchesterUnited |
41+
| 583 | Isabella | 32 | Goalkeeper | Liverpool |
42+
| 388 | Zachary | 24 | Midfielder | BayernMunich |
43+
| 883 | Ava | 23 | Defender | Chelsea |
44+
| 355 | Violet | 18 | Striker | Juventus |
45+
| 247 | Thomas | 27 | Striker | ParisSaint-Germain |
46+
| 761 | Jack | 33 | Midfielder | ManchesterCity |
47+
| 642 | Charlie | 36 | Center-back | Arsenal |
48+
+-----------+----------+-----+-------------+--------------------+<strong>
49+
Output:
50+
</strong>[10, 5]
51+
<strong>Explanation:</strong>
52+
This DataFrame contains 10 rows and 5 columns.
53+
</pre>
54+
55+
## 解法
56+
57+
<!-- 这里可写通用的实现逻辑 -->
58+
59+
<!-- tabs:start -->
60+
61+
### **Pandas**
62+
63+
<!-- 这里可写当前语言的特殊实现逻辑 -->
64+
65+
```python
66+
67+
```
68+
69+
### **...**
70+
71+
```
72+
73+
```
74+
75+
<!-- tabs:end -->
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# [2878. Get the Size of a DataFrame](https://leetcode.com/problems/get-the-size-of-a-dataframe)
2+
3+
[中文文档](/solution/2800-2899/2878.Get%20the%20Size%20of%20a%20DataFrame/README.md)
4+
5+
## Description
6+
7+
<pre>
8+
DataFrame <code>players:</code>
9+
+-------------+--------+
10+
| Column Name | Type |
11+
+-------------+--------+
12+
| player_id | int |
13+
| name | object |
14+
| age | int |
15+
| position | object |
16+
| ... | ... |
17+
+-------------+--------+
18+
</pre>
19+
20+
<p>Write a solution to calculate and display the <strong>number of rows and columns</strong> of <code>players</code>.</p>
21+
22+
<p>Return the result as an array:</p>
23+
24+
<p><code>[number of rows, number of columns]</code></p>
25+
26+
<p>The result format is in the following example.</p>
27+
28+
<p>&nbsp;</p>
29+
<p><strong class="example">Example 1:</strong></p>
30+
31+
<pre>
32+
<strong>Input:
33+
</strong>+-----------+----------+-----+-------------+--------------------+
34+
| player_id | name | age | position | team |
35+
+-----------+----------+-----+-------------+--------------------+
36+
| 846 | Mason | 21 | Forward | RealMadrid |
37+
| 749 | Riley | 30 | Winger | Barcelona |
38+
| 155 | Bob | 28 | Striker | ManchesterUnited |
39+
| 583 | Isabella | 32 | Goalkeeper | Liverpool |
40+
| 388 | Zachary | 24 | Midfielder | BayernMunich |
41+
| 883 | Ava | 23 | Defender | Chelsea |
42+
| 355 | Violet | 18 | Striker | Juventus |
43+
| 247 | Thomas | 27 | Striker | ParisSaint-Germain |
44+
| 761 | Jack | 33 | Midfielder | ManchesterCity |
45+
| 642 | Charlie | 36 | Center-back | Arsenal |
46+
+-----------+----------+-----+-------------+--------------------+<strong>
47+
Output:
48+
</strong>[10, 5]
49+
<strong>Explanation:</strong>
50+
This DataFrame contains 10 rows and 5 columns.
51+
</pre>
52+
53+
## Solutions
54+
55+
<!-- tabs:start -->
56+
57+
### **Pandas**
58+
59+
```python
60+
61+
```
62+
63+
### **...**
64+
65+
```
66+
67+
```
68+
69+
<!-- tabs:end -->
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# [2879. Display the First Three Rows](https://leetcode.cn/problems/display-the-first-three-rows)
2+
3+
[English Version](/solution/2800-2899/2879.Display%20the%20First%20Three%20Rows/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<pre>
10+
DataFrame: <code>employees</code>
11+
+-------------+--------+
12+
| Column Name | Type |
13+
+-------------+--------+
14+
| employee_id | int |
15+
| name | object |
16+
| department | object |
17+
| salary | int |
18+
+-------------+--------+
19+
</pre>
20+
21+
<p>Write a solution to display the <strong>first <code>3</code> </strong>rows<strong> </strong>of this DataFrame.</p>
22+
23+
<p>&nbsp;</p>
24+
<p><strong class="example">Example 1:</strong></p>
25+
26+
<pre>
27+
<strong>Input:
28+
</strong>DataFrame employees
29+
+-------------+-----------+-----------------------+--------+
30+
| employee_id | name | department | salary |
31+
+-------------+-----------+-----------------------+--------+
32+
| 3 | Bob | Operations | 48675 |
33+
| 90 | Alice | Sales | 11096 |
34+
| 9 | Tatiana | Engineering | 33805 |
35+
| 60 | Annabelle | InformationTechnology | 37678 |
36+
| 49 | Jonathan | HumanResources | 23793 |
37+
| 43 | Khaled | Administration | 40454 |
38+
+-------------+-----------+-----------------------+--------+
39+
<strong>Output:</strong>
40+
+-------------+---------+-------------+--------+
41+
| employee_id | name | department | salary |
42+
+-------------+---------+-------------+--------+
43+
| 3 | Bob | Operations | 48675 |
44+
| 90 | Alice | Sales | 11096 |
45+
| 9 | Tatiana | Engineering | 33805 |
46+
+-------------+---------+-------------+--------+
47+
<strong>Explanation:</strong>
48+
Only the first 3 rows are displayed.</pre>
49+
50+
## 解法
51+
52+
<!-- 这里可写通用的实现逻辑 -->
53+
54+
<!-- tabs:start -->
55+
56+
### **Pandas**
57+
58+
<!-- 这里可写当前语言的特殊实现逻辑 -->
59+
60+
```python
61+
62+
```
63+
64+
### **...**
65+
66+
```
67+
68+
```
69+
70+
<!-- tabs:end -->
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# [2879. Display the First Three Rows](https://leetcode.com/problems/display-the-first-three-rows)
2+
3+
[中文文档](/solution/2800-2899/2879.Display%20the%20First%20Three%20Rows/README.md)
4+
5+
## Description
6+
7+
<pre>
8+
DataFrame: <code>employees</code>
9+
+-------------+--------+
10+
| Column Name | Type |
11+
+-------------+--------+
12+
| employee_id | int |
13+
| name | object |
14+
| department | object |
15+
| salary | int |
16+
+-------------+--------+
17+
</pre>
18+
19+
<p>Write a solution to display the <strong>first <code>3</code> </strong>rows<strong> </strong>of this DataFrame.</p>
20+
21+
<p>&nbsp;</p>
22+
<p><strong class="example">Example 1:</strong></p>
23+
24+
<pre>
25+
<strong>Input:
26+
</strong>DataFrame employees
27+
+-------------+-----------+-----------------------+--------+
28+
| employee_id | name | department | salary |
29+
+-------------+-----------+-----------------------+--------+
30+
| 3 | Bob | Operations | 48675 |
31+
| 90 | Alice | Sales | 11096 |
32+
| 9 | Tatiana | Engineering | 33805 |
33+
| 60 | Annabelle | InformationTechnology | 37678 |
34+
| 49 | Jonathan | HumanResources | 23793 |
35+
| 43 | Khaled | Administration | 40454 |
36+
+-------------+-----------+-----------------------+--------+
37+
<strong>Output:</strong>
38+
+-------------+---------+-------------+--------+
39+
| employee_id | name | department | salary |
40+
+-------------+---------+-------------+--------+
41+
| 3 | Bob | Operations | 48675 |
42+
| 90 | Alice | Sales | 11096 |
43+
| 9 | Tatiana | Engineering | 33805 |
44+
+-------------+---------+-------------+--------+
45+
<strong>Explanation:</strong>
46+
Only the first 3 rows are displayed.</pre>
47+
48+
## Solutions
49+
50+
<!-- tabs:start -->
51+
52+
### **Pandas**
53+
54+
```python
55+
56+
```
57+
58+
### **...**
59+
60+
```
61+
62+
```
63+
64+
<!-- tabs:end -->

0 commit comments

Comments
 (0)