From 6a85c58f7a7caf349646896e5c60237a9b8a5211 Mon Sep 17 00:00:00 2001 From: Pranathi Date: Wed, 11 Jun 2025 12:06:04 -0700 Subject: [PATCH] Pandas4 Submitted --- Problem1.py | 12 ++++++++++++ Problem2.py | 12 ++++++++++++ 2 files changed, 24 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..0fe8535 --- /dev/null +++ b/Problem1.py @@ -0,0 +1,12 @@ +import pandas as pd + +def nth_highest_salary(employee: pd.DataFrame, N: int) -> pd.DataFrame: + result_set = set() + for i in range(len(employee)): + salary = employee['salary'][i] + result_set.add(salary) + df = pd.DataFrame(result_set,columns = ['getNthHighestSalary']).sort_values(by = ['getNthHighestSalary'],ascending=False) + if N>len(df) or N<=0: + return pd.DataFrame({f'getNthHighestSalary({N})': [None]}) + else: + return pd.DataFrame({f'getNthHighestSalary({N})': df.iloc[N-1]}) \ No newline at end of file diff --git a/Problem2.py b/Problem2.py new file mode 100644 index 0000000..b8c84ca --- /dev/null +++ b/Problem2.py @@ -0,0 +1,12 @@ +import pandas as pd + +def second_highest_salary(employee: pd.DataFrame) -> pd.DataFrame: + result_set = set() + for i in range(len(employee)): + salary = employee['salary'][i] + result_set.add(salary) + df = pd.DataFrame(result_set,columns = ['SecondHighestSalary']).sort_values(by = ['SecondHighestSalary'],ascending=False) + if len(df)< 2: + return pd.DataFrame({f'SecondHighestSalary': [None]}) + else: + return pd.DataFrame({f'SecondHighestSalary': df.iloc[1]}) \ No newline at end of file