From 805f738a25919efca179dcf99bc94b46c5be9143 Mon Sep 17 00:00:00 2001 From: Radhika Tekade Date: Fri, 7 Mar 2025 09:25:07 -0800 Subject: [PATCH 1/2] Create 137_department_highest_salary --- 137_department_highest_salary.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 137_department_highest_salary.py diff --git a/137_department_highest_salary.py b/137_department_highest_salary.py new file mode 100644 index 0000000..438de74 --- /dev/null +++ b/137_department_highest_salary.py @@ -0,0 +1,11 @@ +# Perform inner join on Employee and Department tables. Get the max salary and return only the rows that +# have max salary. + +import pandas as pd + +def department_highest_salary(employee: pd.DataFrame, department: pd.DataFrame) -> pd.DataFrame: + df = employee.merge(department, left_on='departmentId', right_on='id', how='inner') + max_salary = df.groupby('departmentId')['salary'].transform('max') + df = df[df['salary'] == max_salary] + return (df[['name_y', 'name_x', 'salary']] + .rename(columns= {'name_y': 'Department', 'name_x': 'Employee', 'salary': 'Salary'})) \ No newline at end of file From 9536bb85ace2585b22eb06e62a6927d0a5add3ad Mon Sep 17 00:00:00 2001 From: Radhika Tekade Date: Fri, 7 Mar 2025 09:25:22 -0800 Subject: [PATCH 2/2] Create 138_rank_scores --- 138_rank_scores.py | 8 ++++++++ 1 file changed, 8 insertions(+) create mode 100644 138_rank_scores.py diff --git a/138_rank_scores.py b/138_rank_scores.py new file mode 100644 index 0000000..d34749e --- /dev/null +++ b/138_rank_scores.py @@ -0,0 +1,8 @@ +# Perform Dense Rank on the scores (descending order) and return two columns (scores and rank) in sorted +# ascending order of rank. + +import pandas as pd + +def order_scores(scores: pd.DataFrame) -> pd.DataFrame: + scores['rank'] = scores['score'].rank(method='dense', ascending=False) + return scores[['score', 'rank']].sort_values(by=['rank']) \ No newline at end of file