From 431f0bf381f19d89fc6e6949d286083bd6ee9a2c Mon Sep 17 00:00:00 2001 From: Haswatha Sridharan Date: Wed, 17 Sep 2025 19:00:06 -0500 Subject: [PATCH] Pandas3 Completed --- README.md | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 1d75af9..7ad14bc 100644 --- a/README.md +++ b/README.md @@ -1,12 +1,30 @@ # Pandas3 1 Problem 1 :Calculate Special Bonus ( https://leetcode.com/problems/calculate-special-bonus/) +Solution: + +import pandas as pd + +def calculate_special_bonus(employees: pd.DataFrame) -> pd.DataFrame: + employees['bonus'] = employees['salary'].where( + (~employees['name'].str.startswith('M')) & (employees['employee_id'] % 2 == 1), 0 + ) + return employees[['employee_id', 'bonus']].sort_values('employee_id') 2 Problem 2 : Fix Names in a Table ( https://leetcode.com/problems/fix-names-in-a-table/ ) +Solution: +import pandas as pd +def fix_names(users: pd.DataFrame) -> pd.DataFrame: + users["name"] = users["name"].apply(lambda x: x[0].upper() + x[1:].lower()) + return users.sort_values(by="user_id") 3 Problem 3 : Patients with a Condition ( https://leetcode.com/problems/patients-with-a-condition/) - +Solution: +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