Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CalculateSpecialBonus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
'''
Pandas3

1 Problem 1 :Calculate Special Bonus ( https://leetcode.com/problems/calculate-special-bonus/)

'''

import pandas as pd

def calculate_special_bonus(employees: pd.DataFrame) -> pd.DataFrame:
employees['bonus'] = employees.apply(
lambda x: x['salary'] if (x['employee_id']%2==1) and (x['name'][0]!='M') else 0,axis=1)
return employees[['employee_id', 'bonus']].sort_values('employee_id')
10 changes: 10 additions & 0 deletions FixNamesInATable.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'''
2 Problem 2 : Fix Names in a Table ( https://leetcode.com/problems/fix-names-in-a-table/ )

'''

import pandas as pd

def fix_names(users: pd.DataFrame) -> pd.DataFrame:
users["name"] = users["name"].str[0].str.upper() + users["name"].str[1:].str.lower()
return users[['user_id', 'name']].sort_values('user_id')
9 changes: 9 additions & 0 deletions PatientsWithACondition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
'''
3 Problem 3 : Patients with a Condition ( https://leetcode.com/problems/patients-with-a-condition/)
'''

import pandas as pd

def find_patients(patients: pd.DataFrame) -> pd.DataFrame:
patients = patients[patients['conditions'].str.contains(r"(^|\s)DIAB1", regex=True)]
return patients[['patient_id', 'patient_name', 'conditions']]