Skip to content

Commit a1d1d6b

Browse files
authored
feat: add pandas solution to lc problem: No.0177 (doocs#1860)
1 parent 68ca0f3 commit a1d1d6b

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

Diff for: solution/0100-0199/0177.Nth Highest Salary/README.md

+14
Original file line numberDiff line numberDiff line change
@@ -94,4 +94,18 @@ BEGIN
9494
END
9595
```
9696

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+
97111
<!-- tabs:end -->

Diff for: solution/0100-0199/0177.Nth Highest Salary/README_EN.md

+14
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,18 @@ BEGIN
8686
END
8787
```
8888

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+
89103
<!-- tabs:end -->
+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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})"])

0 commit comments

Comments
 (0)