From 786f64bc25b2cb47b4aef83f17d564339728160d Mon Sep 17 00:00:00 2001 From: BharathVuppala96 Date: Mon, 3 Mar 2025 15:34:55 -0800 Subject: [PATCH] Completed both the problems --- Second highest salary.py | 9 +++++++++ nth highest salary.py | 9 +++++++++ 2 files changed, 18 insertions(+) create mode 100644 Second highest salary.py create mode 100644 nth highest salary.py diff --git a/Second highest salary.py b/Second highest salary.py new file mode 100644 index 0000000..399102a --- /dev/null +++ b/Second highest salary.py @@ -0,0 +1,9 @@ +import pandas as pd + +def second_highest_salary(employee: pd.DataFrame) -> pd.DataFrame: + df=employee['salary'].unique() + df=pd.DataFrame(df,columns=['salary']).sort_values(by=['salary'], ascending=False) + if len(df)<2 or len(df)==0: + return pd.DataFrame({f'SecondHighestSalary':[None]}) + return df.head(2).tail(1)[['salary']].rename(columns={'salary':'SecondHighestSalary'}) + \ No newline at end of file diff --git a/nth highest salary.py b/nth highest salary.py new file mode 100644 index 0000000..62ed27c --- /dev/null +++ b/nth highest salary.py @@ -0,0 +1,9 @@ +import pandas as pd + +def nth_highest_salary(employee: pd.DataFrame, N: int) -> pd.DataFrame: + df= employee['salary'].unique() + df= pd.DataFrame(df,columns=['salary']).sort_values(by=['salary'],ascending=False) + if N>len(df) or N <=0: + return pd.DataFrame({f'getNthHighestSalary({N})' : [None]}) + return df.head(N).tail(1)[['salary']].rename(columns={'salary':f'getNthHighestSalary({N})'}) + \ No newline at end of file