From 8e30ae9e41cbff87d3dcaa9837680385d1eeecd9 Mon Sep 17 00:00:00 2001 From: Punya Ira Anand Date: Thu, 27 Feb 2025 19:55:14 -0600 Subject: [PATCH 1/3] Create Calculate Special Bonus --- Calculate Special Bonus | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Calculate Special Bonus diff --git a/Calculate Special Bonus b/Calculate Special Bonus new file mode 100644 index 0000000..d83cfd3 --- /dev/null +++ b/Calculate Special Bonus @@ -0,0 +1,18 @@ +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] + # 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']) + #df =employees['name'] + +#df[''] ==df[''] is an iterable object -->Series +#from df extract a list + 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') From 46b10ba539d073c181a05f1a34db7b5794deb089 Mon Sep 17 00:00:00 2001 From: Punya Ira Anand Date: Thu, 27 Feb 2025 19:55:56 -0600 Subject: [PATCH 2/3] Create Fix Names in a Table --- Fix Names in a Table | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 Fix Names in a Table diff --git a/Fix Names in a Table b/Fix Names in a Table new file mode 100644 index 0000000..17940a4 --- /dev/null +++ b/Fix Names in a Table @@ -0,0 +1,9 @@ +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']) + + #easy way - use capitalize method. + users['name'] = users['name'].str.capitalize() + return users.sort_values(by=['user_id']) From 0311745ba9c7787a988ece3a7928aa1d494b530f Mon Sep 17 00:00:00 2001 From: Punya Ira Anand Date: Thu, 27 Feb 2025 20:36:11 -0600 Subject: [PATCH 3/3] Create Patients With a Condition --- Patients With a Condition | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 Patients With a Condition diff --git a/Patients With a Condition b/Patients With a Condition new file mode 100644 index 0000000..482b59e --- /dev/null +++ b/Patients With a Condition @@ -0,0 +1,28 @@ +import pandas as pd + +def find_patients(patients: pd.DataFrame) -> pd.DataFrame: + #condition - diab1 is there for diabetes + #follwoing is a long way of solving the query + #1 + + # 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 conditions.startswith('DIAB1'): + # result.append([p_id,p_name,condition]) + # break + # return pd.DataFrame(result,columns =['patient_id', 'patient_name','conditions']) + + #a little shorter approach + + #2 + df = patients[(patients['conditions'].str.startswith('DIAB1')) | (patients['conditions'].str.contains('DIAB1'))] + return df + + #the most simplest way - + #3 + #return patients[patients['conditions'].str.contains(r"(^|\s)DIAB1", regex=True)] +