Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Pandas Dataframe how to get multiple rows where a column is equal to a specific value

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading