From 7e299b1a0d8949bcfc6295ce645fd84a7e66e8e8 Mon Sep 17 00:00:00 2001 From: Mayuri Mhatre Date: Tue, 18 Mar 2025 19:17:36 -0500 Subject: [PATCH] Done PR --- Problem1.py | 13 +++++++++++++ Problem2.py | 9 +++++++++ 2 files changed, 22 insertions(+) create mode 100644 Problem1.py create mode 100644 Problem2.py diff --git a/Problem1.py b/Problem1.py new file mode 100644 index 0000000..e38e2d3 --- /dev/null +++ b/Problem1.py @@ -0,0 +1,13 @@ +import pandas as pd + +def department_highest_salary(employee: pd.DataFrame, department: pd.DataFrame) -> pd.DataFrame: + merged_data = employee.merge(department, how='left', left_on='departmentId', right_on='id') + + max_salaries = merged_data.groupby('departmentId')['salary'].transform(max) + + highest_salary_employees = merged_data[merged_data['salary'] == max_salaries] + + result = highest_salary_employees[['name_y', 'name_x', 'salary']].rename( + columns={'name_y': 'Department', 'name_x': 'Employee', 'salary': 'Salary'}) + + return result \ No newline at end of file diff --git a/Problem2.py b/Problem2.py new file mode 100644 index 0000000..807e8ac --- /dev/null +++ b/Problem2.py @@ -0,0 +1,9 @@ +import pandas as pd + +def order_scores(scores: pd.DataFrame) -> pd.DataFrame: + scores.sort_values(by=['score'], inplace=True, ascending=False, ignore_index=True) + scores['rank']=scores['score'].rank(method='dense', ascending=False) + + result= scores[['score', 'rank']] + + return result \ No newline at end of file