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
9 changes: 9 additions & 0 deletions 132_calculate_special_bonus.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Create new column 'bonus' with if else condition such that 'bonus' == 'salary' if employee_id is even
# and the 'name' does not start with M. Sort the resulting df and return in ascending order of id.

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 and not \
x['name'].startswith('M') else 0, axis=1)
return employees[['employee_id', 'bonus']].sort_values(by=['employee_id'])
8 changes: 8 additions & 0 deletions 133_fix_names_in_table.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Changed the 'name' by using the function 'str.capitalize()' and return the resulting df in ascending
# user_id.

import pandas as pd

def fix_names(users: pd.DataFrame) -> pd.DataFrame:
users['name'] = users['name'].str.capitalize()
return users.sort_values(by=['user_id'])
10 changes: 10 additions & 0 deletions 134_patients_with_condition.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Since there are multiple conditions, we need to look for two things, conditions that startswith 'DIAB1'
# and conditions that contain ' DIAB1'. Note the "contain" has a blank space at the start for the spaces
# between words.

import pandas as pd

def find_patients(patients: pd.DataFrame) -> pd.DataFrame:
df = patients[(patients['conditions'].str.startswith('DIAB1')) | \
(patients['conditions'].str.contains(' DIAB1'))]
return df