From a2872829c9cfc036a56141bdbd537aa30529c1b5 Mon Sep 17 00:00:00 2001 From: Pranathi Date: Tue, 10 Jun 2025 18:42:06 -0700 Subject: [PATCH] Pandas3 Submitted --- Problem1.py | 14 ++++++++++++++ Problem2.py | 5 +++++ Problem3.py | 14 ++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 Problem1.py create mode 100644 Problem2.py create mode 100644 Problem3.py diff --git a/Problem1.py b/Problem1.py new file mode 100644 index 0000000..5844747 --- /dev/null +++ b/Problem1.py @@ -0,0 +1,14 @@ +import pandas as pd + +def calculate_special_bonus(employees: pd.DataFrame) -> pd.DataFrame: + result = [] + for i in range(len(employees)): + e_id = employees['employee_id'][i] + name = employees['name'][i] + salary = employees['salary'][i] + + if (e_id % 2 !=0) and (name[0]!='M'): + result.append([e_id, employees['salary'][i]]) + else: + result.append([e_id, 0]) + return pd.DataFrame(result, columns = ['employee_id','bonus']).sort_values(by = ['employee_id']) \ No newline at end of file diff --git a/Problem2.py b/Problem2.py new file mode 100644 index 0000000..9a0e491 --- /dev/null +++ b/Problem2.py @@ -0,0 +1,5 @@ +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/Problem3.py b/Problem3.py new file mode 100644 index 0000000..59cde85 --- /dev/null +++ b/Problem3.py @@ -0,0 +1,14 @@ +import pandas as pd + +def find_patients(patients: pd.DataFrame) -> pd.DataFrame: + result = [] + for i in range(len(patients)): + p_id = patients['patient_id'][i] + p_name = patients['patient_name'][i] + conditions = patients['conditions'][i] + for condition in conditions.split(): + if condition.startswith('DIAB1'): + result.append([p_id,p_name,conditions]) + break + return pd.DataFrame(result, columns = ['patient_id','patient_name','conditions']) + \ No newline at end of file