From 53e9b19c56d3bd0610450322c28f1dd187ef12eb Mon Sep 17 00:00:00 2001 From: Radhika Tekade Date: Tue, 4 Mar 2025 15:00:10 -0800 Subject: [PATCH 1/3] Create 132_calculate_special_bonus --- 132_calculate_special_bonus.py | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 132_calculate_special_bonus.py diff --git a/132_calculate_special_bonus.py b/132_calculate_special_bonus.py new file mode 100644 index 0000000..70d8193 --- /dev/null +++ b/132_calculate_special_bonus.py @@ -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']) \ No newline at end of file From 05bd2e7beb3d9a3c34ec08a2f779a6dfcc25b14a Mon Sep 17 00:00:00 2001 From: Radhika Tekade Date: Tue, 4 Mar 2025 15:00:31 -0800 Subject: [PATCH 2/3] Create 133_fix_names_in_table --- 133_fix_names_in_table.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 133_fix_names_in_table.py diff --git a/133_fix_names_in_table.py b/133_fix_names_in_table.py new file mode 100644 index 0000000..ab09b61 --- /dev/null +++ b/133_fix_names_in_table.py @@ -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']) \ No newline at end of file From cdc5ff035e8842d2f55d0e5a6707ea6f0ef01c54 Mon Sep 17 00:00:00 2001 From: Radhika Tekade Date: Tue, 4 Mar 2025 15:00:49 -0800 Subject: [PATCH 3/3] Create 134_patients_with_conditions --- 134_patients_with_condition.py | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 134_patients_with_condition.py diff --git a/134_patients_with_condition.py b/134_patients_with_condition.py new file mode 100644 index 0000000..9f1995c --- /dev/null +++ b/134_patients_with_condition.py @@ -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 \ No newline at end of file