I am trying to create a dataframe that contains the entire row value from another dataframe if a specific column is equal to a value. The issue is that I need to do this for 2 different columns. So far my attempts sort of work, but the result is that the second call to the dataframe overwrites the first.
subsetDataFrame = df[df['Base Price Check'] == 'False']
subsetDataFrame = df[df['MSRP Price Check'] == 'False']
All I want is to either combine this into one line, or somehow make 2 work. This will not work as I expect if the MSRP Price Check column is something other than false. It overwrites the first column. I feel this should be an easy fix but I have not found it yet.
CodePudding user response:
Combine them via logical operators: and &
, or |
, not ~
.
subsetDataFrame = df[(df['Base Price Check'] == 'False') & (df['MSRP Price Check'] == 'False')]
The above code is going to filter rows where both Base Price Check
and MSRP Price Check
is False
(you can alter your logic accordingly).