python pandas 3 smallest & 3 largest values

前端 未结 5 1040
误落风尘
误落风尘 2021-01-20 03:03

How can I find the index of the 3 smallest and 3 largest values in a column in my pandas dataframe? I saw ways to find max and min, but none to get the 3.

5条回答
  •  暗喜
    暗喜 (楼主)
    2021-01-20 03:39

    What have you tried? You could sort with s.sort() and then call s.head(3).index and s.tail(3).index.

提交回复
热议问题