When I have a dataframe
df = DataFrame({'A': [5, 6, 3, 4], 'B': [1, 2, 3, 5]})
df
A B
0 5 1
1 6 2
2 3 3
3 4 5
I can use
df[df['A'].isin([3, 6])]
in order to select rows having the passed values.
Is there also a way to keep the order of the input list?
So that my output is not:
A B
1 6 2
2 3 3
but
A B
1 3 3
2 6 2
df[...]with boolean indexing keeps the order of the DataFrame, regardless of whether the...part involvesisinor not. You would have to reorder your DataFrame separately, before or after applyingisin.isinis only for checking whether each item at a time "is in" the list at all, not where it is in the list. It doesn't pay attention to the list's order. Like I said, you would need to do the ordering in a separate step.