File tree 3 files changed +38
-0
lines changed
solution/0100-0199/0177.Nth Highest Salary
3 files changed +38
-0
lines changed Original file line number Diff line number Diff line change 94
94
END
95
95
```
96
96
97
+ ``` python
98
+ import pandas as pd
99
+
100
+
101
+ def nth_highest_salary (employee : pd.DataFrame, N : int ) -> pd.DataFrame:
102
+ unique_salaries = employee.salary.unique()
103
+ if len (unique_salaries) < N:
104
+ return pd.DataFrame([np.NaN], columns = [f " getNthHighestSalary( { N} ) " ])
105
+ else :
106
+ salary = sorted (unique_salaries, reverse = True )[N - 1 ]
107
+ return pd.DataFrame([salary], columns = [f " getNthHighestSalary( { N} ) " ])
108
+
109
+ ```
110
+
97
111
<!-- tabs:end -->
Original file line number Diff line number Diff line change 86
86
END
87
87
```
88
88
89
+ ``` python
90
+ import pandas as pd
91
+
92
+
93
+ def nth_highest_salary (employee : pd.DataFrame, N : int ) -> pd.DataFrame:
94
+ unique_salaries = employee.salary.unique()
95
+ if len (unique_salaries) < N:
96
+ return pd.DataFrame([np.NaN], columns = [f " getNthHighestSalary( { N} ) " ])
97
+ else :
98
+ salary = sorted (unique_salaries, reverse = True )[N - 1 ]
99
+ return pd.DataFrame([salary], columns = [f " getNthHighestSalary( { N} ) " ])
100
+
101
+ ```
102
+
89
103
<!-- tabs:end -->
Original file line number Diff line number Diff line change
1
+ import pandas as pd
2
+
3
+
4
+ def nth_highest_salary (employee : pd .DataFrame , N : int ) -> pd .DataFrame :
5
+ unique_salaries = employee .salary .unique ()
6
+ if len (unique_salaries ) < N :
7
+ return pd .DataFrame ([np .NaN ], columns = [f"getNthHighestSalary({ N } )" ])
8
+ else :
9
+ salary = sorted (unique_salaries , reverse = True )[N - 1 ]
10
+ return pd .DataFrame ([salary ], columns = [f"getNthHighestSalary({ N } )" ])
You can’t perform that action at this time.
0 commit comments