I'd like to group this data frame by the values in zipcode column, and return in another (called rate) column the second lowest rate or the lowest rate or the max rate.
For example, from this df:
zipcode state county_code name rate_area_x plan_id metal_level rate rate_area_y
36749 AL 1001 Autauga 11 52161YL6358432 Silver 245.82 6
36749 AL 1001 Autauga 11 01100AO4222848 Silver 271.77 5
36749 AL 1001 Autauga 11 24848KC5063721 Silver 264.84 1
36749 AL 1001 Autauga 11 89885YK0256118 Silver 269.11 8
36749 AL 1001 Autauga 11 65392ON5819785 Silver 305.02 12
30165 AL 1019 Cherokee 13 52161YL6358432 Silver 245.82 6
30165 AL 1019 Cherokee 13 01100AO4222848 Silver 271.77 5
30165 AL 1019 Cherokee 13 24848KC5063721 Silver 264.84 1
30165 AL 1019 Cherokee 13 89885YK0256118 Silver 269.11 8
30165 AL 1019 Cherokee 13 65392ON5819785 Silver 305.02 12
30165 AL 1019 Cherokee 13 90884WN5801293 Silver 323.25 2
30165 AL 1019 Cherokee 13 79113BU1788705 Silver 344.81 7
I'd expect:
zipcode rate
36749 245.82
30165 245.82
In R I'd do this to get the min value for each zipcode group:
grouped_df <- df %>%
group_by(zipcode) %>%
summarise(rate = min(rate))
But how to get the second lowest rate value using Python's Pandas?