From ea7ee7eac5af09ec319b39aa677721494fdf3769 Mon Sep 17 00:00:00 2001 From: tejas274 Date: Tue, 10 Jun 2025 14:58:33 -0500 Subject: [PATCH 1/2] problem 1 and 2 added --- problem1-1873-calculate-special-bonus.py | 31 ++++++++++++++++++++++++ problem2-1667-fix-names-table.py | 7 ++++++ 2 files changed, 38 insertions(+) create mode 100644 problem1-1873-calculate-special-bonus.py create mode 100644 problem2-1667-fix-names-table.py diff --git a/problem1-1873-calculate-special-bonus.py b/problem1-1873-calculate-special-bonus.py new file mode 100644 index 0000000..0435260 --- /dev/null +++ b/problem1-1873-calculate-special-bonus.py @@ -0,0 +1,31 @@ +import pandas as pd + +def calculate_special_bonus(employees: pd.DataFrame) -> pd.DataFrame: + + for i in range(0,len(employees)): + e_id = employees['employee_id'][i] + e_name = employees['name'][i] + if(e_id %2 == 0) or (e_name[0] == 'M'): + employees['salary'][i] = 0 + + df = employees[['employee_id','salary']] + + return df.sort_values(by = ['employee_id']).rename(columns = {'salary':'bonus'}) + + +###better sol + +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']) + + + + + diff --git a/problem2-1667-fix-names-table.py b/problem2-1667-fix-names-table.py new file mode 100644 index 0000000..1da6ee9 --- /dev/null +++ b/problem2-1667-fix-names-table.py @@ -0,0 +1,7 @@ +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.sort_values(by=['user_id']) \ No newline at end of file From 20c24508ca8041eef6929e1ce74d8eb34e0d0d1a Mon Sep 17 00:00:00 2001 From: tejas274 Date: Wed, 11 Jun 2025 11:43:22 -0500 Subject: [PATCH 2/2] problem 3 added --- problem3-1527-patients-with-condition.py | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 problem3-1527-patients-with-condition.py diff --git a/problem3-1527-patients-with-condition.py b/problem3-1527-patients-with-condition.py new file mode 100644 index 0000000..79046b2 --- /dev/null +++ b/problem3-1527-patients-with-condition.py @@ -0,0 +1,5 @@ +import pandas as pd + + +def find_patients(patients: pd.DataFrame) -> pd.DataFrame: + return patients[(patients['conditions'].str.startswith("DIAB1") | patients['conditions'].str.contains(" DIAB1"))] \ No newline at end of file