diff --git a/Problem1.py b/Problem1.py new file mode 100644 index 0000000..4d11f3d --- /dev/null +++ b/Problem1.py @@ -0,0 +1,9 @@ +import pandas as pd + +def nth_highest_salary(employee: pd.DataFrame, N: int) -> pd.DataFrame: + colname = f'getNthHighestSalary({N})' + array_values = sorted(employee['salary'].unique(), reverse = True) + if N >= 1 and len(array_values) >= N : + return pd.DataFrame({colname: [array_values[N-1]]}) + + return pd.DataFrame({colname: [None]}) \ No newline at end of file diff --git a/Problem2.py b/Problem2.py new file mode 100644 index 0000000..2e42b3a --- /dev/null +++ b/Problem2.py @@ -0,0 +1,12 @@ +import pandas as pd + +def second_highest_salary(employee: pd.DataFrame) -> pd.DataFrame: + unique_salaries = employee['salary'].drop_duplicates() + + if len(unique_salaries) >= 2: + second_highest = unique_salaries.nlargest(2).iloc[-1] + else: + second_highest = None + + result_df = pd.DataFrame({'SecondHighestSalary': [second_highest]}) + return result_df \ No newline at end of file