Reputation: 125
I am looking to filter a dataframe to only include values that are equal to a certain value, or greater than another value.
Example dataframe:
0 1 2
0 0 1 23
1 0 2 43
2 1 3 54
3 2 3 77
From here, I want to pull all values from column 0, where column 2 is either equal to 23, or greater than 50 (so it should return 0, 1 and 2). Here is the code I have so far:
df = df[(df[2]=23) & (df[2]>50)]
This returns nothing. However, when I split these apart and run them individually (df = df[df[2]=23]
and df = df[df[2]>50]
), then I do get results back. Does anyone have any insights onto how to get this to work?
Upvotes: 0
Views: 952
Reputation: 13748
As you said , it's or
: |
not and
: &
df = df[(df[2]=23) | (df[2]>50)]
Upvotes: 1