From a9296a3d1f400739c811c9e738b81f4bd3b0407b Mon Sep 17 00:00:00 2001 From: Hinduja Cheela Date: Thu, 19 Jun 2025 18:54:57 -0500 Subject: [PATCH] Added two problems --- problem1.py | 8 ++++++++ problem2.py | 9 +++++++++ 2 files changed, 17 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..f90f0a5 --- /dev/null +++ b/problem1.py @@ -0,0 +1,8 @@ +import pandas as pd + +def nth_highest_salary(employee: pd.DataFrame, N: int) -> pd.DataFrame: + df=employee[['salary']].drop_duplicates() + if N < 0 or N>len(df): + return pd.DataFrame({f'getNthHighestSalary({N})':[None]}) + new_df=df.sort_values(by=['salary'],ascending=False).head(N).tail(1).rename(columns={'salary':f'getNthHighestSalary({N})'}) + return new_df \ No newline at end of file diff --git a/problem2.py b/problem2.py new file mode 100644 index 0000000..7a48dd2 --- /dev/null +++ b/problem2.py @@ -0,0 +1,9 @@ +import pandas as pd + +def second_highest_salary(employee: pd.DataFrame) -> pd.DataFrame: + second=employee['salary'].drop_duplicates().sort_values(ascending=False) + if len(second)>=2: + result=second.head(2).tail(1) + else: + result=pd.Series([None]) + return pd.DataFrame({'SecondHighestSalary':result.reset_index(drop=True)}) \ No newline at end of file