LeetCode 2886: Change Data Type

Problem Description

Explanation:

To correct the errors in the DataFrame by converting the grade column from floats to integers, we can iterate through each row and convert the grade value to an integer. This can be done by casting the float value to an integer. The algorithm is straightforward and has a time complexity of O(n), where n is the number of rows in the DataFrame. The space complexity is O(1) as we are not using any extra space.

:

Solutions

public void changeDataType(DataFrame students) {
    for (int i = 0; i < students.size(); i++) {
        int grade = (int) students.get(i).get("grade");
        students.get(i).put("grade", grade);
    }
}

Loading editor...