From d5c0c7a2a5916a55c3972b0a415fcf52f96a57c9 Mon Sep 17 00:00:00 2001 From: rakeshchary25119 Date: Fri, 20 Sep 2024 21:18:21 -0500 Subject: [PATCH] Pandas4 Solutions --- nthHighestSalary.py | 8 ++++++++ secondHighestSalary.py | 12 ++++++++++++ 2 files changed, 20 insertions(+) create mode 100644 nthHighestSalary.py create mode 100644 secondHighestSalary.py diff --git a/nthHighestSalary.py b/nthHighestSalary.py new file mode 100644 index 0000000..ca350b9 --- /dev/null +++ b/nthHighestSalary.py @@ -0,0 +1,8 @@ +import pandas as pd + +def nth_highest_salary(employee: pd.DataFrame, N: int) -> pd.DataFrame: + if N <= len(employee) and N > 0: + + return employee + else: + return pd.DataFrame({f'getNthHighestSalary({N})':[None]}) \ No newline at end of file diff --git a/secondHighestSalary.py b/secondHighestSalary.py new file mode 100644 index 0000000..c54b3b6 --- /dev/null +++ b/secondHighestSalary.py @@ -0,0 +1,12 @@ +import pandas as pd + +def second_highest_salary(employee: pd.DataFrame) -> pd.DataFrame: + second_highest_salary = list(employee['salary'].unique()) + + + if len(second_highest_salary)<2: + result = [None] + else: + second_highest_salary.sort(reverse = True) + result = [second_highest_salary[1]] + return pd.DataFrame(result, columns = ['SecondHighestSalary']) \ No newline at end of file