From a8c3b2309f94dc1f8379be29c9c19ae48f8fe239 Mon Sep 17 00:00:00 2001 From: Avdhut Pailwan Date: Sun, 21 Jul 2024 21:21:19 +0530 Subject: [PATCH 1/3] [Documentation Update]: Add Solution to LeetCode Problem No 2883 Fixes issue #3707 --- .../2800-2899/2883-Drop-Missing-Data.md | 101 ++++++++++++++++++ 1 file changed, 101 insertions(+) create mode 100644 dsa-solutions/lc-solutions/2800-2899/2883-Drop-Missing-Data.md diff --git a/dsa-solutions/lc-solutions/2800-2899/2883-Drop-Missing-Data.md b/dsa-solutions/lc-solutions/2800-2899/2883-Drop-Missing-Data.md new file mode 100644 index 000000000..1999d37e9 --- /dev/null +++ b/dsa-solutions/lc-solutions/2800-2899/2883-Drop-Missing-Data.md @@ -0,0 +1,101 @@ +--- +id: Drop-Missing-Data +title: Drop Missing Data Solution +sidebar_label: 2883 - Drop Missing Data +tags: + - LeetCode + - Python +description: "This is a solution to the Drop Missing Data problem on LeetCode." +sidebar_position: 1 +--- + +In this tutorial, we will solve the Drop Missing Data problem. We will provide the implementation of the solution in Python. + +## Problem Description + +```plaintext +DataFrame students ++-------------+--------+ +| Column Name | Type | ++-------------+--------+ +| student_id | int | +| name | object | +| age | int | ++-------------+--------+ +``` + +There are some rows having missing values in the name column. + +Write a solution to remove the rows with missing values. + +### Examples + +**Example 1:** + +```plaintext +Input: ++------------+---------+-----+ +| student_id | name | age | ++------------+---------+-----+ +| 32 | Piper | 5 | +| 217 | None | 19 | +| 779 | Georgia | 20 | +| 849 | Willow | 14 | ++------------+---------+-----+ + +Output: ++------------+---------+-----+ +| student_id | name | age | ++------------+---------+-----+ +| 32 | Piper | 5 | +| 779 | Georgia | 20 | +| 849 | Willow | 14 | ++------------+---------+-----+ + +Explanation: +Student with id 217 havs empty value in the name column, so it will be removed. +``` + +### Constraints + +- You have to solve using python pandas only. + +--- + +## Solution for Drop Missing Data + + + + + +```py +import pandas as pd + +def dropMissingData(students: pd.DataFrame) -> pd.DataFrame: + return students[students['name'].notnull()] +``` + + + + +#### Complexity Analysis + +- **Time Complexity:** $O(n)$ +- **Space Complexity:** $O(n)$ +- **Iterating over the DataFrame:** The notnull() function on the 'name' column performs an O(n) operation, iterating through each row of the DataFrame, where n is the number of rows. +- **Boolean indexing:** Usually an O(n) process, this involves building a new DataFrame from the boolean mask (the output of notnull()). +- **New DataFrame:** To hold the filtered data, the function builds a new DataFrame. The number of rows with complete "name" values determines the size of this new DataFrame, and in the worst scenario, that number may reach n. + As a result, O(n) is also the space complexity. + + + + +--- + +

Authors:

+ +
+{['avdhut-pailwan'].map(username => ( + +))} +
From 4ff0dd7c237dbad14ec35902cd11822e1fde9d5d Mon Sep 17 00:00:00 2001 From: Avdhut Pailwan Date: Sun, 21 Jul 2024 21:32:12 +0530 Subject: [PATCH 2/3] styling changes --- .../lc-solutions/2800-2899/2883-Drop-Missing-Data.md | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/dsa-solutions/lc-solutions/2800-2899/2883-Drop-Missing-Data.md b/dsa-solutions/lc-solutions/2800-2899/2883-Drop-Missing-Data.md index 1999d37e9..fb75b366c 100644 --- a/dsa-solutions/lc-solutions/2800-2899/2883-Drop-Missing-Data.md +++ b/dsa-solutions/lc-solutions/2800-2899/2883-Drop-Missing-Data.md @@ -64,10 +64,6 @@ Student with id 217 havs empty value in the name column, so it will be removed. ## Solution for Drop Missing Data - - - - ```py import pandas as pd @@ -75,10 +71,7 @@ def dropMissingData(students: pd.DataFrame) -> pd.DataFrame: return students[students['name'].notnull()] ``` - - - -#### Complexity Analysis +### Complexity Analysis - **Time Complexity:** $O(n)$ - **Space Complexity:** $O(n)$ @@ -87,9 +80,6 @@ def dropMissingData(students: pd.DataFrame) -> pd.DataFrame: - **New DataFrame:** To hold the filtered data, the function builds a new DataFrame. The number of rows with complete "name" values determines the size of this new DataFrame, and in the worst scenario, that number may reach n. As a result, O(n) is also the space complexity. - - - ---

Authors:

From 6504b1b5bbe9a2a4a0f3a050c3ec773caa6a9e87 Mon Sep 17 00:00:00 2001 From: "Restyled.io" Date: Sun, 21 Jul 2024 16:02:27 +0000 Subject: [PATCH 3/3] Restyled by whitespace --- dsa-solutions/lc-solutions/2800-2899/2883-Drop-Missing-Data.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dsa-solutions/lc-solutions/2800-2899/2883-Drop-Missing-Data.md b/dsa-solutions/lc-solutions/2800-2899/2883-Drop-Missing-Data.md index fb75b366c..8ae1b2d8c 100644 --- a/dsa-solutions/lc-solutions/2800-2899/2883-Drop-Missing-Data.md +++ b/dsa-solutions/lc-solutions/2800-2899/2883-Drop-Missing-Data.md @@ -77,7 +77,7 @@ def dropMissingData(students: pd.DataFrame) -> pd.DataFrame: - **Space Complexity:** $O(n)$ - **Iterating over the DataFrame:** The notnull() function on the 'name' column performs an O(n) operation, iterating through each row of the DataFrame, where n is the number of rows. - **Boolean indexing:** Usually an O(n) process, this involves building a new DataFrame from the boolean mask (the output of notnull()). -- **New DataFrame:** To hold the filtered data, the function builds a new DataFrame. The number of rows with complete "name" values determines the size of this new DataFrame, and in the worst scenario, that number may reach n. +- **New DataFrame:** To hold the filtered data, the function builds a new DataFrame. The number of rows with complete "name" values determines the size of this new DataFrame, and in the worst scenario, that number may reach n. As a result, O(n) is also the space complexity. ---