diff --git a/Calculate Special Bonus.py b/Calculate Special Bonus.py new file mode 100644 index 0000000..e9e3132 --- /dev/null +++ b/Calculate Special Bonus.py @@ -0,0 +1,33 @@ +import pandas as pd + +def calculate_special_bonus(employees: pd.DataFrame) -> pd.DataFrame: + #sol1 + # 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') + + #sol2 + # for i in range(len(employees)): + # e_id = employees['employee_id'][i] + # name = employees['name'][i] + + # if (e_id % 2 == 0) or (name[0] == 'M'): + # employees['salary'][i] = 0 + # df = employees[['employee_id', 'salary']] + # return df.rename(columns = {'salary':'bonus'}).sort_values(by = 'employee_id') + + #sol3 + 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.py b/Fix Names in a Table.py new file mode 100644 index 0000000..2dbd078 --- /dev/null +++ b/Fix Names in a Table.py @@ -0,0 +1,8 @@ +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() + 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.py b/Patients With a Condition.py new file mode 100644 index 0000000..0ed007d --- /dev/null +++ b/Patients With a Condition.py @@ -0,0 +1,26 @@ +import pandas as pd + +def find_patients(patients: pd.DataFrame) -> pd.DataFrame: + #sol1 + # result = [] + + # for i in range(len(patients)): + # patient_id = patients['patient_id'][i] + # patient_name = patients['patient_name'][i] + # conditions = patients['conditions'][i] + + # for condition in conditions.split(): + # if condition.startswith('DIAB1'): + # result.append([patient_id,patient_name,conditions]) + # break + + # return pd.DataFrame(result, columns =['patient_id','patient_name','conditions']) + + #sol2 + # patients = patients[patients['conditions'].str.startswith('DIAB1')| + # patients['conditions'].str.contains(' DIAB1') ] + # return patients + + #sol3 + return patients[patients['conditions'].str.contains( r"(^|\s)DIAB1", regex =True)] + \ No newline at end of file