Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit d4f2b3c

Browse files
Add new file
1 parent 7d82559 commit d4f2b3c

File tree

1 file changed

+48
-0
lines changed

1 file changed

+48
-0
lines changed
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
"""
2+
2886. Change Data Type
3+
Solved
4+
Easy
5+
Companies
6+
Hint
7+
8+
DataFrame students
9+
+-------------+--------+
10+
| Column Name | Type |
11+
+-------------+--------+
12+
| student_id | int |
13+
| name | object |
14+
| age | int |
15+
| grade | float |
16+
+-------------+--------+
17+
18+
Write a solution to correct the errors:
19+
20+
The grade column is stored as floats, convert it to integers.
21+
22+
The result format is in the following example.
23+
24+
Example 1:
25+
Input:
26+
DataFrame students:
27+
+------------+------+-----+-------+
28+
| student_id | name | age | grade |
29+
+------------+------+-----+-------+
30+
| 1 | Ava | 6 | 73.0 |
31+
| 2 | Kate | 15 | 87.0 |
32+
+------------+------+-----+-------+
33+
Output:
34+
+------------+------+-----+-------+
35+
| student_id | name | age | grade |
36+
+------------+------+-----+-------+
37+
| 1 | Ava | 6 | 73 |
38+
| 2 | Kate | 15 | 87 |
39+
+------------+------+-----+-------+
40+
Explanation:
41+
The data types of the column grade is converted to int.
42+
"""
43+
44+
import pandas as pd
45+
46+
def changeDatatype(students: pd.DataFrame) -> pd.DataFrame:
47+
students['grade'] = students['grade'].astype(int)
48+
return students

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /