diff --git a/Nth Highest Salary b/Nth Highest Salary new file mode 100644 index 0000000..403edb1 --- /dev/null +++ b/Nth Highest Salary @@ -0,0 +1,10 @@ + +import pandas as pd + +def nth_highest_salary(employee: pd.DataFrame, N: int) -> pd.DataFrame: + df =employee['salary'].drop_duplicates().sort_values(ascending=False) + if N>len(df) or N<=0: + return pd.DataFrame({f'getNthHighestSalary({N})': [None]}) + else: + df2 = df.iloc[N-1] + return pd.DataFrame({f'getNthHighestSalary({N})':[df2]}) diff --git a/Second Highest Salary b/Second Highest Salary new file mode 100644 index 0000000..490e53f --- /dev/null +++ b/Second Highest Salary @@ -0,0 +1,7 @@ + +import pandas as pd + +def second_highest_salary(employee: pd.DataFrame) -> pd.DataFrame: + unique_salaries = employee['salary'].drop_duplicates().nlargest(2) #multiple entries avoided + second_highest = unique_salaries.iloc[1] if len(unique_salaries) > 1 else None #to find out the seond highest salary + return pd.DataFrame({'SecondHighestSalary': [second_highest]}) #renaming the column