From 7f5c6af3746c77e9b74a0a1182723e318992aba7 Mon Sep 17 00:00:00 2001 From: Dhruv Parashar Date: Tue, 10 Jun 2025 21:32:07 -0400 Subject: [PATCH] Done Pandas3 --- Calculate Special Bonus | 6 ++++++ Fix Names in a Table | 7 +++++++ Patients with a Condition | 7 +++++++ 3 files changed, 20 insertions(+) create mode 100644 Calculate Special Bonus create mode 100644 Fix Names in a Table create mode 100644 Patients with a Condition diff --git a/Calculate Special Bonus b/Calculate Special Bonus new file mode 100644 index 0000000..6b54938 --- /dev/null +++ b/Calculate Special Bonus @@ -0,0 +1,6 @@ +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 b/Fix Names in a Table new file mode 100644 index 0000000..88d8465 --- /dev/null +++ b/Fix Names in a Table @@ -0,0 +1,7 @@ +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 diff --git a/Patients with a Condition b/Patients with a Condition new file mode 100644 index 0000000..79fd37a --- /dev/null +++ b/Patients with a Condition @@ -0,0 +1,7 @@ +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[['patient_id', 'patient_name', 'conditions']] \ No newline at end of file