I'm new at Python and I want to filter rows by multiple column values.
The name of my dataframe is df, the column name is values and I want to filter this column by the following values:
2, 4, 5, 9
My dataframe is like this:
name value
Jon 4
Ron 5
Paul 10
Max 3
So grateful, Henrique.
There are two ways to do this:
df[(df["value"]==2) | (df["value"]==4) | (df["value"]==5) | (df["value"]==9)]
OR
numbers = [2, 4, 5, 9]
df[df["value"].isin(numbers)]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With