Return dataframe subset based on a list of boolean values

前端 未结 6 2230
星月不相逢
星月不相逢 2021-02-13 04:38

I\'m trying to slice a dataframe based on list of values, how would I go about this?

Say I have an expression or a list l = [0,1,0,0,1,1,0,0,0,1]

Ho

6条回答
  •  抹茶落季
    2021-02-13 05:22

    Or maybe find the position of 1 in your list and slice from the Dataframe

    df.loc[[i for i,x in enumerate(lst) if x == 1],:]
    

提交回复
热议问题