diff --git a/problem1-1873-calculate-special-bonus.py b/problem1-1873-calculate-special-bonus.py new file mode 100644 index 0000000..0435260 --- /dev/null +++ b/problem1-1873-calculate-special-bonus.py @@ -0,0 +1,31 @@ +import pandas as pd + +def calculate_special_bonus(employees: pd.DataFrame) -> pd.DataFrame: + + for i in range(0,len(employees)): + e_id = employees['employee_id'][i] + e_name = employees['name'][i] + if(e_id %2 == 0) or (e_name[0] == 'M'): + employees['salary'][i] = 0 + + df = employees[['employee_id','salary']] + + return df.sort_values(by = ['employee_id']).rename(columns = {'salary':'bonus'}) + + +###better sol + +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 and not x['name'].startswith('M') else 0, + axis=1) + + return employees[['employee_id', 'bonus']].sort_values(by=['employee_id']) + + + + + diff --git a/problem2-1667-fix-names-table.py b/problem2-1667-fix-names-table.py new file mode 100644 index 0000000..1da6ee9 --- /dev/null +++ b/problem2-1667-fix-names-table.py @@ -0,0 +1,7 @@ +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-1527-patients-with-condition.py b/problem3-1527-patients-with-condition.py new file mode 100644 index 0000000..79046b2 --- /dev/null +++ b/problem3-1527-patients-with-condition.py @@ -0,0 +1,5 @@ +import pandas as pd + + +def find_patients(patients: pd.DataFrame) -> pd.DataFrame: + return patients[(patients['conditions'].str.startswith("DIAB1") | patients['conditions'].str.contains(" DIAB1"))] \ No newline at end of file