Skip to content

Commit 17cedee

Browse files
authored
feat: add pandas solutions to lc problems: No.2877~2891 (doocs#1750)
* No.2877.Create a DataFrame from List * No.2878.Get the Size of a DataFrame * No.2879.Display the First Three Rows * No.2880.Select Data * No.2881.Create a New Column * No.2882.Drop Duplicate Rows * No.2883.Drop Missing Data * No.2884.Modify Columns * No.2885.Rename Columns * No.2886.Change Data Type * No.2887.Fill Missing Data * No.2888.Reshape Data Concatenate * No.2889.Reshape Data Pivot * No.2890.Reshape Data Melt * No.2891.Method Chaining
1 parent 99c4667 commit 17cedee

File tree

45 files changed

+222
-20
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+222
-20
lines changed

solution/2800-2899/2877.Create a DataFrame from List/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,11 @@ A DataFrame was created on top of student_data, with two columns named <code>stu
4848
<!-- 这里可写当前语言的特殊实现逻辑 -->
4949

5050
```python
51+
import pandas as pd
5152

53+
54+
def createDataframe(student_data: List[List[int]]) -> pd.DataFrame:
55+
return pd.DataFrame(student_data, columns=['student_id', 'age'])
5256
```
5357

5458
### **...**

solution/2800-2899/2877.Create a DataFrame from List/README_EN.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,11 @@ A DataFrame was created on top of student_data, with two columns named <code>stu
4242
### **Pandas**
4343

4444
```python
45+
import pandas as pd
4546

47+
48+
def createDataframe(student_data: List[List[int]]) -> pd.DataFrame:
49+
return pd.DataFrame(student_data, columns=['student_id', 'age'])
4650
```
4751

4852
### **...**
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import pandas as pd
2+
3+
4+
def createDataframe(student_data: List[List[int]]) -> pd.DataFrame:
5+
return pd.DataFrame(student_data, columns=['student_id', 'age'])

solution/2800-2899/2878.Get the Size of a DataFrame/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,11 @@ This DataFrame contains 10 rows and 5 columns.
6363
<!-- 这里可写当前语言的特殊实现逻辑 -->
6464

6565
```python
66+
import pandas as pd
6667

68+
69+
def getDataframeSize(players: pd.DataFrame) -> List[int]:
70+
return list(players.shape)
6771
```
6872

6973
### **...**

solution/2800-2899/2878.Get the Size of a DataFrame/README_EN.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,11 @@ This DataFrame contains 10 rows and 5 columns.
5757
### **Pandas**
5858

5959
```python
60+
import pandas as pd
6061

62+
63+
def getDataframeSize(players: pd.DataFrame) -> List[int]:
64+
return list(players.shape)
6165
```
6266

6367
### **...**
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import pandas as pd
2+
3+
4+
def getDataframeSize(players: pd.DataFrame) -> List[int]:
5+
return list(players.shape)

solution/2800-2899/2879.Display the First Three Rows/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ Only the first 3 rows are displayed.</pre>
5858
<!-- 这里可写当前语言的特殊实现逻辑 -->
5959

6060
```python
61+
import pandas as pd
6162

63+
64+
def selectFirstRows(employees: pd.DataFrame) -> pd.DataFrame:
65+
return employees.head(3)
6266
```
6367

6468
### **...**

solution/2800-2899/2879.Display the First Three Rows/README_EN.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ Only the first 3 rows are displayed.</pre>
5252
### **Pandas**
5353

5454
```python
55+
import pandas as pd
5556

57+
58+
def selectFirstRows(employees: pd.DataFrame) -> pd.DataFrame:
59+
return employees.head(3)
5660
```
5761

5862
### **...**
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
import pandas as pd
2+
3+
4+
def selectFirstRows(employees: pd.DataFrame) -> pd.DataFrame:
5+
return employees.head(3)

solution/2800-2899/2880.Select Data/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,11 @@ Input:</strong>
5454
<!-- 这里可写当前语言的特殊实现逻辑 -->
5555

5656
```python
57+
import pandas as pd
5758

59+
60+
def selectData(students: pd.DataFrame) -> pd.DataFrame:
61+
return students[students['student_id'] == 101][['name', 'age']]
5862
```
5963

6064
### **Java**

0 commit comments

Comments
 (0)