Change Data Type — LeetCode 2886 Python Solution
EasyPandas
- Problem
- #2886
- Reading time
- 2 min
- Source
- leetcode.com
Table schema
SQL
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
SQL
DataFrame students
+-------------+--------+
| Column Name | Type |
+-------------+--------+
| student_id | int |
| name | object |
| age | int |
| grade | float |
+-------------+--------+Python solution
Python
import pandas as pd
def changeDatatype(students: pd.DataFrame) -> pd.DataFrame:
students['grade'] = students['grade'].astype(int)
return studentsComplexity
| Measure | Complexity |
|---|---|
| Time | O(n) |
| Space | O(1) to O(n) auxiliary |
Related problems
Frequently asked questions
- How hard is LeetCode 2886. Change Data Type?
- LeetCode 2886. Change Data Type is rated Easy on LeetCode.
- What topics does LeetCode 2886. Change Data Type cover?
- LeetCode 2886. Change Data Type is tagged Pandas on LeetCode.