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]
l = [0,1,0,0,1,1,0,0,0,1]
Ho
yet another "creative" approach:
In [181]: a = np.array(lst) In [182]: df.query("index * @a > 0") Out[182]: 0 1 2 1 1 5 5 4 0 2 0 5 4 9 9 9 2 2 5
or much better variant from @ayhan:
In [183]: df.query("@a != 0") Out[183]: 0 1 2 1 1 5 5 4 0 2 0 5 4 9 9 9 2 2 5
PS i've also borrowed @Ayhan's setup