From e5bf1dac515a0e931cfc7ea2cce1b6a06763c141 Mon Sep 17 00:00:00 2001 From: Paneri Patel Date: Wed, 18 Jun 2025 16:17:46 -0400 Subject: [PATCH] Done Pandas3 --- CalculateSpecialBonus.py | 13 +++++++++++++ FixNamesInATable.py | 10 ++++++++++ PatientsWithACondition.py | 9 +++++++++ 3 files changed, 32 insertions(+) create mode 100644 CalculateSpecialBonus.py create mode 100644 FixNamesInATable.py create mode 100644 PatientsWithACondition.py diff --git a/CalculateSpecialBonus.py b/CalculateSpecialBonus.py new file mode 100644 index 0000000..7110970 --- /dev/null +++ b/CalculateSpecialBonus.py @@ -0,0 +1,13 @@ +''' +Pandas3 + +1 Problem 1 :Calculate Special Bonus ( https://leetcode.com/problems/calculate-special-bonus/) + +''' + +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==1) and (x['name'][0]!='M') else 0,axis=1) + return employees[['employee_id', 'bonus']].sort_values('employee_id') \ No newline at end of file diff --git a/FixNamesInATable.py b/FixNamesInATable.py new file mode 100644 index 0000000..888b22e --- /dev/null +++ b/FixNamesInATable.py @@ -0,0 +1,10 @@ +''' +2 Problem 2 : Fix Names in a Table ( https://leetcode.com/problems/fix-names-in-a-table/ ) + +''' + +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[['user_id', 'name']].sort_values('user_id') \ No newline at end of file diff --git a/PatientsWithACondition.py b/PatientsWithACondition.py new file mode 100644 index 0000000..d70df4a --- /dev/null +++ b/PatientsWithACondition.py @@ -0,0 +1,9 @@ +''' +3 Problem 3 : Patients with a Condition ( https://leetcode.com/problems/patients-with-a-condition/) +''' + +import pandas as pd + +def find_patients(patients: pd.DataFrame) -> pd.DataFrame: + patients = patients[patients['conditions'].str.contains(r"(^|\s)DIAB1", regex=True)] + return patients[['patient_id', 'patient_name', 'conditions']] \ No newline at end of file