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
Convert the list to a boolean array and then use boolean indexing:
df = pd.DataFrame(np.random.randint(10, size=(10, 3))) df[np.array(lst).astype(bool)] Out: 0 1 2 1 8 6 3 4 2 7 3 5 7 2 3 9 1 3 4