Pandas (and numpy) allow for boolean indexing, which will be much more efficient:

In [11]: df.loc[df['col1'] >= 1, 'col1']
Out[11]: 
1    1
2    2
Name: col1

In [12]: df[df['col1'] >= 1]
Out[12]: 
   col1  col2
1     1    11
2     2    12

In [13]: df[(df['col1'] >= 1) & (df['col1'] <=1 )]
Out[13]: 
   col1  col2
1     1    11

If you want to write helper functions for this, consider something along these lines:

In [14]: def b(x, col, op, n): 
             return op(x[col],n)

In [15]: def f(x, *b):
             return x[(np.logical_and(*b))]

In [16]: b1 = b(df, 'col1', ge, 1)

In [17]: b2 = b(df, 'col1', le, 1)

In [18]: f(df, b1, b2)
Out[18]: 
   col1  col2
1     1    11

Update: pandas 0.13 has a query method for these kind of use cases, assuming column names are valid identifiers the following works (and can be more efficient for large frames as it uses numexpr behind the scenes):

In [21]: df.query('col1 <= 1 & 1 <= col1')
Out[21]:
   col1  col2
1     1    11
Answer from Andy Hayden on Stack Overflow
🌐
GeeksforGeeks
geeksforgeeks.org › python › filter-pandas-dataframe-with-multiple-conditions
Filter Pandas Dataframe with multiple conditions - GeeksforGeeks
July 23, 2025 - The reason is dataframe may be having multiple columns and multiple rows. Selective display of columns with limited rows is always the expected view of users. To fulfill the user's expectations and also help in machine deep learning scenarios, filtering of Pandas dataframe with multiple conditions is much necessary.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas filter dataframe by multiple conditions
Pandas Filter DataFrame by Multiple Conditions - Spark By {Examples}
October 3, 2024 - How to Filter Pandas DataFrame by multiple conditions? By using df[], loc[], query(), eval() and numpy.where() we can filter Pandas DataFrame by multiple
Discussions

python - Pandas: Filtering multiple conditions - Stack Overflow
I'm trying to do boolean indexing with a couple conditions using Pandas. My original DataFrame is called df. If I perform the below, I get the expected result: temp = df[df["bin"] == 3] temp = t... More on stackoverflow.com
🌐 stackoverflow.com
Pandas - Filter based on multiple conditions
You can filter rows by using "boolean indexing", and as with all boolean expressions you can combine multiple conditions with "and", "or, "any", and "all" operations. Here is an example using "and", the syntax for that is " & "; note that neither condition on it's own would give the results that the conjunction of the 2 conditions does. >>> df = pd.DataFrame({"a":[1, 3, 5], "b":[2, 4, 6], "c":[7, 14, 1]}) >>> df a b c 0 1 2 7 1 3 4 14 2 5 6 1 >>> df[(df.c <= 7)] a b c 0 1 2 7 2 5 6 1 >>> df[(df.a <= 3)] a b c 0 1 2 7 1 3 4 14 >>> df[(df.a <= 3) & (df.c <= 7)] a b c 0 1 2 7 BTW, I don't see how having the column names as a list of strings would be much help, but you _could_ do something using the df["column"] syntax like: >>> def myfilt(df, labels): ... return df[(df[labels[0]] <= 3) & (df[labels[1]] <= 7)] ... >>> control_fields = ["a", "c"] >>> myfilt(df, control_fields) a b c 0 1 2 7 >>> https://pandas-docs.github.io/pandas-docs-travis/user_guide/indexing.html#boolean-indexing More on reddit.com
🌐 r/learnpython
6
1
January 17, 2021
pandas - Filter rows with multiple conditions using two dataframes - Data Science Stack Exchange
I have two dataframes that share an ID number column. I'd like to filter df1's rows based on two conditions: 1) it shares the ID with df2 and 2) it meets a condition in a column in df2. I have this... More on datascience.stackexchange.com
🌐 datascience.stackexchange.com
June 24, 2023
Panda - filter multiple columns by multiple values
You can use .isin(): RawData["Column3"].isin(["AAA", "BBB"]) More on reddit.com
🌐 r/learnpython
7
1
June 21, 2024
Top answer
1 of 7
393

Pandas (and numpy) allow for boolean indexing, which will be much more efficient:

In [11]: df.loc[df['col1'] >= 1, 'col1']
Out[11]: 
1    1
2    2
Name: col1

In [12]: df[df['col1'] >= 1]
Out[12]: 
   col1  col2
1     1    11
2     2    12

In [13]: df[(df['col1'] >= 1) & (df['col1'] <=1 )]
Out[13]: 
   col1  col2
1     1    11

If you want to write helper functions for this, consider something along these lines:

In [14]: def b(x, col, op, n): 
             return op(x[col],n)

In [15]: def f(x, *b):
             return x[(np.logical_and(*b))]

In [16]: b1 = b(df, 'col1', ge, 1)

In [17]: b2 = b(df, 'col1', le, 1)

In [18]: f(df, b1, b2)
Out[18]: 
   col1  col2
1     1    11

Update: pandas 0.13 has a query method for these kind of use cases, assuming column names are valid identifiers the following works (and can be more efficient for large frames as it uses numexpr behind the scenes):

In [21]: df.query('col1 <= 1 & 1 <= col1')
Out[21]:
   col1  col2
1     1    11
2 of 7
65

Chaining conditions creates long lines, which are discouraged by PEP8. Using the .query method forces to use strings, which is powerful but unpythonic and not very dynamic.

Once each of the filters is in place, one approach could be:

import numpy as np
import functools
def conjunction(*conditions):
    return functools.reduce(np.logical_and, conditions)

c_1 = data.col1 == True
c_2 = data.col2 < 64
c_3 = data.col3 != 4

data_filtered = data[conjunction(c_1,c_2,c_3)]

np.logical operates on and is fast, but does not take more than two arguments, which is handled by functools.reduce.

Note that this still has some redundancies:

  • Shortcutting does not happen on a global level
  • Each of the individual conditions runs on the whole initial data

Still, I expect this to be efficient enough for many applications and it is very readable. You can also make a disjunction (wherein only one of the conditions needs to be true) by using np.logical_or instead:

import numpy as np
import functools
def disjunction(*conditions):
    return functools.reduce(np.logical_or, conditions)

c_1 = data.col1 == True
c_2 = data.col2 < 64
c_3 = data.col3 != 4

data_filtered = data[disjunction(c_1,c_2,c_3)]
🌐
Statology
statology.org › home › how to filter a pandas dataframe on multiple conditions
How to Filter a Pandas DataFrame on Multiple Conditions
August 19, 2020 - #define a list of values filter_list = [12, 14, 15] #return only rows where points is in the list of values df[df.points.isin(filter_list)] team points assists rebounds 1 A 12 7 8 2 B 15 7 10 3 B 14 9 6 #define another list of values filter_list2 = ['A', 'C'] #return only rows where team is in the list of values df[df.team.isin(filter_list2)] team points assists rebounds 0 A 25 5 11 1 A 12 7 8 4 C 19 12 6 · You can find more pandas tutorials here.
🌐
Towards Data Science
towardsdatascience.com › home › data science › stop writing messy boolean masks: 10 elegant ways to filter pandas dataframes
Stop Writing Messy Boolean Masks: 10 Elegant Ways to Filter Pandas DataFrames | Towards Data Science
January 22, 2026 - The ampersand (&) symbol represents AND in pandas. We use this when we’re trying to fulfil two conditions. In this case, both conditions have to be true. For instance, let’s retrieve orders from the “Furniture” category where Price > 500.
🌐
Reddit
reddit.com › r/learnpython › pandas - filter based on multiple conditions
r/learnpython on Reddit: Pandas - Filter based on multiple conditions
January 17, 2021 -

Hi,

I have a csv file with approx. 100 columns and I want to filter rows if two of the columns are set to a value of X and the other columns are blank / Nan values. In order to make the code more readable, I would like to specify the column names in a list and then use the variable name within the Pandas query e.g. something like the following:

 

my_file=/home/test.csv
my_df=pd.read_csv(my_file)

control_fields=['Is_Active','Is_Valid']  
data_fields=['Age','DOB','Country','City']  

 

As a starting point, I have tried the following but this isn't filtering the data at all:

 

my_new_df=my_df[my_df['control_fields']==1]

 

Can someone please explain why the above isn't working and also advise if there is a better way of achieving my requirement?

Thanks!

Find elsewhere
🌐
Saturn Cloud
saturncloud.io › blog › pandas-filtering-multiple-conditions
Pandas Filtering Multiple Conditions | Saturn Cloud Blog
May 1, 2026 - The most commonly used functions are loc and iloc. The loc function is used to filter data based on labels, while the iloc function is used to filter data based on integer positions.
🌐
Like Geeks
likegeeks.com › home › python › pandas › filter using pandas query method with multiple conditions
Filter Using Pandas query method with multiple conditions
You can use parentheses to dictate the order in which conditions are evaluated in the query method. Suppose you want to select records where either the Age is greater than 24 and the Salary is less than 70000, or the Age is less than 25. filtered_df = df.query("(Age > 24 & Salary < 70000) | (Age < 25)") print(filtered_df) ... Here, parentheses make it clear that the AND operation (&) should be carried out before the OR operation (|). In the context of Pandas query method, you can integrate regex to add another dimension to your data filtering capabilities.
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Select rows by multiple conditions | note.nkmk.me
August 8, 2023 - pandas: Extract rows that contain ... To filter rows based on multiple conditions, apply the &, |, and ~ operators for AND, OR, and NOT respectively to multiple Boolean Series....
🌐
Stack Exchange
datascience.stackexchange.com › questions › 122370 › filter-rows-with-multiple-conditions-using-two-dataframes
pandas - Filter rows with multiple conditions using two dataframes - Data Science Stack Exchange
June 24, 2023 - I have two dataframes that share an ID number column. I'd like to filter df1's rows based on two conditions: 1) it shares the ID with df2 and 2) it meets a condition in a column in df2. I have this...
🌐
Saturn Cloud
saturncloud.io › blog › how-to-use-pandas-to-check-multiple-columns-for-a-condition
How to Use Pandas to Check Multiple Columns for a Condition | Saturn Cloud Blog
May 1, 2026 - Using boolean indexing to filter ... a function to multiple columns · The loc method is a powerful tool for selecting rows and columns from a Pandas dataframe based on specific conditions....
🌐
YouTube
youtube.com › watch
How to Filter Data in Python Pandas with Multiple Conditions (Step-by-Step) - YouTube
🧠 Don’t miss out! Get FREE access to my Skool community — packed with resources, tools, and support to help you with Data, Machine Learning, and AI Automati...
Published: April 18, 2025
🌐
Python Guides
pythonguides.com › pandas-filter-multiple-conditions
Filter DataFrames with Multiple Conditions in Python Pandas
May 5, 2026 - I often run into situations where I need to filter a column against a list of specific values. Instead of writing five different OR conditions, I use the .isin() method. It is much more efficient. Let’s say we have a dataset of US retail stores and we only want to see data for stores located in “New York”, “Texas”, or “California”. import pandas as pd # Sample Retail Store data retail_data = { 'StoreID': [101, 102, 103, 104, 105, 106], 'State': ['NY', 'NJ', 'TX', 'CA', 'FL', 'TX'], 'Sales_k': [500, 300, 450, 700, 250, 400] } df_retail = pd.DataFrame(retail_data) # List of states we are interested in target_states = ['NY', 'TX', 'CA'] # Filtering using .isin() filtered_retail = df_retail[df_retail['State'].isin(target_states)] print("Sales data for target states:") print(filtered_retail)
🌐
Data Science Parichay
datascienceparichay.com › article › pandas-filter-dataframe-for-multiple-conditions
Pandas - Filter DataFrame for multiple conditions
Two thumbs up - I recently switched to WPX Hosting and recommend their speed, service and security - they do know what they are talking about when it comes to WordPress hosting.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas filter rows by conditions
Pandas Filter Rows by Conditions - Spark By {Examples}
June 4, 2025 - You can filter the rows from Pandas DataFrame based on a single condition or multiple conditions using either loc[], query(), or apply() function. In this
🌐
Medium
medium.com › @priyarajtt › filter-pandas-dataframe-with-multiple-conditions-6eb9805f9f41
Filter Pandas Dataframe with multiple conditions | by priya raj | Medium
June 4, 2021 - # filter dataframe display(dataFrame.query(‘Salary <= 100000 & Age < 40 & JOB.str.startswith(“C”).values’)) ... Method 4: pandas Boolean indexing multiple conditions standard way (“Boolean indexing” works with values in a column only)
🌐
Easy Tweaks
easytweaks.com › pandas-select-filter-columns-multiple-conditions
How to filter rows by multiple conditions in Pandas?
August 23, 2022 - Master meetings, chats, channels and online collaboration · Go beyond the basics in Word, Excel, PowerPoint and Outlook
🌐
KDnuggets
kdnuggets.com › 2022 › 12 › five-ways-conditional-filtering-pandas.html
Five Ways to do Conditional Filtering in Pandas - KDnuggets
If we want to make our multi-condition search, we can put each individual filters inside parentheses () separated by our Boolean search criteria (& for and, | for or, and ~ for not).
🌐
GeeksforGeeks
geeksforgeeks.org › select-rows-with-multiple-filters-in-pandas
Select Rows With Multiple Filters in Pandas | GeeksforGeeks
January 24, 2021 - In this article, let's learn to select the rows from Pandas DataFrame based on some conditions. Syntax: df.loc[df['cname'] 'condition'] Parameters: df: represents data frame cname: represent ... The "NOT IN"(∼) filter is a membership operator used to check whether the data is present in DataFrame or not. Pandas library does not have the direct NOT IN filter in Python, but we can perform the NOT IN filter by negating the isin() operator of Pandas.