
Sponsored
Sponsored
This approach leverages a filtering method to iterate over each row and eliminate the rows with missing 'name' values. The method checks for nullity in the 'name' column and keeps only those rows where 'name' is not null.
Time Complexity: O(n), where n is the number of rows, as we potentially check each row.
Space Complexity: O(1), as we are modifying the DataFrame in place (though Pandas may create a copy depending on the operation).
1function dropMissingData(students) {
2 The JavaScript solution uses the filter method over the array of student objects. This method creates a new array with only the elements that pass the condition specified in the callback function, i.e., where the 'name' is not null.
This approach manually iterates over each row in the dataset, checking if the 'name' field is missing. Rows with missing 'name' values are filtered out, which can be useful in environments that lack high-level filtering functions.
Time Complexity: O(n), to iterate over each student.
Space Complexity: O(n), to store the valid students in the new array.
1#include <stdio.h>
2#include <stdlib.h>
3#include <string.h>
4
5typedef struct {
6 int student_id;
7 char *name;
8 int age;
9} Student;
10
11Student* dropMissingData(Student* students, int size, int* newSize) {
12 Student* validStudents = malloc(size * sizeof(Student));
13 int index = 0;
14 for (int i = 0; i < size; i++) {
15 if (students[i].name != NULL) {
16 validStudents[index++] = students[i];
17 }
18 }
19 *newSize = index;
20 return validStudents;
21}
22This C program defines a structure Student and iterates over each student, checking if the name is NULL. Valid entries are copied to a new array, which is returned after the loop.