-
-
Notifications
You must be signed in to change notification settings - Fork 155
Added solutions for the LC problems from 2880-2882 #568
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 3 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6af0e9a
Create 2880 - Select Data
Abhay182005dat d722d4a
Create 2881 - Create a New Column
Abhay182005dat a2ffb14
Create 2882 - Drop Duplicate Rows
Abhay182005dat a6cdf2e
Update 2880 - Select Data
Abhay182005dat 684f17a
Update 2881 - Create a New Column
Abhay182005dat d225cd7
Update 2882 - Drop Duplicate Rows
Abhay182005dat d28daeb
Create Flex-Box Properties
Abhay182005dat b59be09
Update 2880 - Select Data
ajay-dhangar 21420fa
Update Flex-Box Properties
ajay-dhangar File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
--- | ||
id : Select Data | ||
title : Select Data from a DataFrame | ||
sidebar_label: 2880 Select Data Leetcode | ||
tags: | ||
- LeetCode | ||
- Python | ||
- Data Science | ||
description: "This is a solution to the Select Data question from the Leetcode 2880 question" | ||
--- | ||
|
||
## Problem Description | ||
|
||
Write a solution to select the name and age of the student with student_id = 101. | ||
|
||
##Examples | ||
|
||
Example 1: | ||
|
||
Input: | ||
+------------+---------+-----+ | ||
| student_id | name | age | | ||
+------------+---------+-----+ | ||
| 101 | Ulysses | 13 | | ||
| 53 | William | 10 | | ||
| 128 | Henry | 6 | | ||
| 3 | Henry | 11 | | ||
+------------+---------+-----+ | ||
|
||
Output: | ||
+---------+-----+ | ||
| name | age | | ||
+---------+-----+ | ||
| Ulysses | 13 | | ||
+---------+-----+ | ||
|
||
##Intuition | ||
I will say as this is a Data Science Problem the solution is also straightforward . Hope it helps :) | ||
. | ||
|
||
### Solution Code | ||
<Tabs> | ||
ajay-dhangar marked this conversation as resolved.
Show resolved
Hide resolved
|
||
<TabItem value="Python" label="" default> | ||
<SolutionAuthor name="@Abhay:)"/> | ||
```Python | ||
import pandas as pd | ||
|
||
def selectData(students: pd.DataFrame) -> pd.DataFrame: | ||
return students.loc[students['student_id'] == 101, ["name", "age"]] | ||
## References | ||
- **Leetcode Problem :** [Select Data](https://leetcode.com/problems/select-data/) |
60 changes: 60 additions & 0 deletions
60
dsa-solutions/lc-solutions/2500 - 3000/2881 - Create a New Column
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
--- | ||
id : Create-a-New-Column | ||
title : Create a New column | ||
sidebar_label: 2881 Create a new column Leetcode | ||
tags: | ||
- LeetCode | ||
- Python | ||
- Data Science | ||
description: "This is a solution for the leetcode 2881 problem which is to create a new column.This problem uses pandas which is a python library for solving" | ||
--- | ||
|
||
## Problem Description | ||
|
||
A company plans to provide its employees with a bonus. | ||
Write a solution to create a new column name bonus that contains the doubled values of the salary column. | ||
|
||
##Examples | ||
|
||
Input: | ||
DataFrame employees | ||
+---------+--------+ | ||
| name | salary | | ||
+---------+--------+ | ||
| Piper | 4548 | | ||
| Grace | 28150 | | ||
| Georgia | 1103 | | ||
| Willow | 6593 | | ||
| Finn | 74576 | | ||
| Thomas | 24433 | | ||
+---------+--------+ | ||
Output: | ||
+---------+--------+--------+ | ||
| name | salary | bonus | | ||
+---------+--------+--------+ | ||
| Piper | 4548 | 9096 | | ||
| Grace | 28150 | 56300 | | ||
| Georgia | 1103 | 2206 | | ||
| Willow | 6593 | 13186 | | ||
| Finn | 74576 | 149152 | | ||
| Thomas | 24433 | 48866 | | ||
+---------+--------+--------+ | ||
Explanation: | ||
A new column bonus is created by doubling the value in the column salary. | ||
|
||
##Intuition | ||
I will say as this is a Data Science Problem the solution is also straightforward . Hope it helps :) | ||
. | ||
|
||
### Solution Code | ||
<Tabs> | ||
<TabItem value="Python" label="" default> | ||
<SolutionAuthor name="@Abhay:)"/> | ||
```Python | ||
import pandas as pd | ||
|
||
def createBonusColumn(employees: pd.DataFrame) -> pd.DataFrame: | ||
employees['bonus'] = employees['salary']*2 | ||
return employees | ||
## References | ||
- **Leetcode Problem :** [Create a new column](https://leetcode.com/problems/create-a-new-column/) |
62 changes: 62 additions & 0 deletions
62
dsa-solutions/lc-solutions/2500 - 3000/2882 - Drop Duplicate Rows
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
--- | ||
id : Drop-Duplicate-Rows | ||
title : Drop Duplicate Rows | ||
sidebar_label: 2882 Drop Duplicate Rows | ||
tags: | ||
- LeetCode | ||
- Python | ||
- Data Science | ||
description: "This is a solution for the Leetcode problem 2882 which asks to drop duplicate rows and keep only the first occurence. | ||
This Problem is solved with the help of python library Pandas. " | ||
--- | ||
|
||
## Problem Description | ||
|
||
There are some duplicate rows in the DataFrame based on the email column. | ||
Write a solution to remove these duplicate rows and keep only the first occurrence. | ||
The result format is in the following example. | ||
|
||
##Examples | ||
|
||
Example 1: | ||
Input: | ||
+-------------+---------+---------------------+ | ||
| customer_id | name | email | | ||
+-------------+---------+---------------------+ | ||
| 1 | Ella | emily@example.com | | ||
| 2 | David | michael@example.com | | ||
| 3 | Zachary | sarah@example.com | | ||
| 4 | Alice | john@example.com | | ||
| 5 | Finn | john@example.com | | ||
| 6 | Violet | alice@example.com | | ||
+-------------+---------+---------------------+ | ||
Output: | ||
+-------------+---------+---------------------+ | ||
| customer_id | name | email | | ||
+-------------+---------+---------------------+ | ||
| 1 | Ella | emily@example.com | | ||
| 2 | David | michael@example.com | | ||
| 3 | Zachary | sarah@example.com | | ||
| 4 | Alice | john@example.com | | ||
| 6 | Violet | alice@example.com | | ||
+-------------+---------+---------------------+ | ||
Explanation: | ||
Alic (customer_id = 4) and Finn (customer_id = 5) both use john@example.com, so only the first occurrence of this email is retained. | ||
|
||
##Intuition | ||
I will say as this is a Data Science Problem the solution is also straightforward . Hope it helps :) | ||
. | ||
|
||
### Solution Code | ||
<Tabs> | ||
<TabItem value="Python" label="" default> | ||
<SolutionAuthor name="@Abhay:)"/> | ||
```Python | ||
import pandas as pd | ||
|
||
def dropDuplicateEmails(customers: pd.DataFrame) -> pd.DataFrame: | ||
customers.drop_duplicates(subset='email',keep='first',inplace = True) | ||
return customers | ||
|
||
## References | ||
- **Leetcode Problem :** [Drop Duplicate Rows](https://leetcode.com/problems/drop-duplicate-rows/description/) |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.