Select Pandas rows based on list index

前端 未结 5 661
滥情空心
滥情空心 2020-11-28 03:37

I have a dataframe df :

   20060930  10.103       NaN     10.103   7.981
   20061231  15.915       NaN     15.915  12.686
   20070331   3.196       NaN               


        
5条回答
  •  甜味超标
    2020-11-28 03:57

    There are many ways of solving this problem, and the ones listed above are the most commonly used ways of achieving the solution. I want to add two more ways, just in case someone is looking for an alternative.

    index_list = [1,3]
    
    df.take(pos)
    
    #or
    
    df.query('index in @index_list')
    

提交回复
热议问题