From 78600684601bd88a33ad0f6c74bc9984236387e2 Mon Sep 17 00:00:00 2001 From: Bharath Vuppala Date: Thu, 27 Feb 2025 23:19:14 -0800 Subject: [PATCH] 3 problems completed --- Calculate Special Bonus.py | 9 +++++++++ Fix names in a table.py | 7 +++++++ Patients with a condition.py | 6 ++++++ 3 files changed, 22 insertions(+) create mode 100644 Calculate Special Bonus.py create mode 100644 Fix names in a table.py create mode 100644 Patients with a condition.py diff --git a/Calculate Special Bonus.py b/Calculate Special Bonus.py new file mode 100644 index 0000000..f0441a9 --- /dev/null +++ b/Calculate Special Bonus.py @@ -0,0 +1,9 @@ +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 diff --git a/Fix names in a table.py b/Fix names in a table.py new file mode 100644 index 0000000..bbbb342 --- /dev/null +++ b/Fix names in a 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 diff --git a/Patients with a condition.py b/Patients with a condition.py new file mode 100644 index 0000000..e55950b --- /dev/null +++ b/Patients with a condition.py @@ -0,0 +1,6 @@ +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