Premium problem118. Second-Highest Distinct Salary per Department

Medium Locked

employees has columns employee_id, department and salary.

Return a Series indexed by department giving the second-highest distinct salary in each one, sorted by department. Two people on the same top salary do not make that salary the second-highest. A department with fewer than two distinct salaries yields NaN.

Input

   employee_id department  salary
0            1        Eng     130
1            2        Eng     130
2            3        Eng     120
3            4        Ops      70
4            5        Ops      88
5            6         HR      50

Output

department
Eng    120.0
HR       NaN
Ops     70.0
Name: salary, dtype: float64

Premium problem

This one's part of Premium. Unlock the full Pandas track plus every other premium problem on the site.

Implement solve(...)