You can use the isin method:
In [1]: df = pd.DataFrame({'A': [5,6,3,4], 'B': [1,2,3,5]})
In [2]: df
Out[2]:
A B
0 5 1
1 6 2
2 3 3
3 4 5
In [3]: df[df['A'].isin([3, 6])]
Out[3]:
A B
1 6 2
2 3 3
And to get the opposite use ~:
In [4]: df[~df['A'].isin([3, 6])]
Out[4]:
A B
0 5 1
3 4 5
Answer from Wouter Overmeire on Stack Overflow Top answer 1 of 9
2291
You can use the isin method:
In [1]: df = pd.DataFrame({'A': [5,6,3,4], 'B': [1,2,3,5]})
In [2]: df
Out[2]:
A B
0 5 1
1 6 2
2 3 3
3 4 5
In [3]: df[df['A'].isin([3, 6])]
Out[3]:
A B
1 6 2
2 3 3
And to get the opposite use ~:
In [4]: df[~df['A'].isin([3, 6])]
Out[4]:
A B
0 5 1
3 4 5
2 of 9
104
You can use the method query:
df.query('A in [6, 3]')
# df.query('A == [6, 3]')
or
lst = [6, 3]
df.query('A in @lst')
# df.query('A == @lst')
How can I get a List of unique values in a column?
u/Mugiwara_JTres3 - Your post was submitted successfully. Once your problem is solved, reply to the answer(s) saying Solution Verified to close the thread. Follow the submission rules -- particularly 1 and 2. To fix the body, click edit. To fix your title, delete and re-post. Include your Excel version and all other relevant information Failing to follow these steps may result in your post being removed without warning. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns. More on reddit.com
How can I use the filter in a pandas data frame using a dictionary containing some values?
Firstly, this is a pandas question that is unrelated to django…? Also your variable dict is not a dictionary but a simple list. You can load your CSV into a pandas dataframe and then filter it with filtered_df = df[df.B.isin(dict)] More on reddit.com
How do I filter a dataframe based on if a certain string is contained within a list stored in a column?
figured it out - it's the first code snippet but you need "regex=False" set in the contains() method (there are underscore characters in my strings which was probably messing something up) More on reddit.com
using pandas column value to filter columns.
Think about which dataframe you're referencing in your filtering and start with how you would do this operation if you were just passing a list of static values as columns to be selected into the new dataframe. Maybe you don't need to do this many operations to access the values you need. Also consider whether .isin is the best method to use here given that it returns booleans. Maybe .values is more appropriate to reference the items in the "new" series. More on reddit.com
Mark Needham
markhneedham.com › blog › 2021 › 03 › 28 › pandas-column-value-in-array-list-truth-value-ambiguous
Pandas: Filter column value in array/list - ValueError: The truth value of a Series is ambiguous | Mark Needham
March 28, 2021 - In this post we'll learn how to filter a Pandas DataFrame based on a column value existing in an array/list.
Saturn Cloud
saturncloud.io › blog › how-to-filter-for-a-list-of-values-in-python-pandas-using-loc
How to Filter for a List of Values in Python Pandas Using Loc | Saturn Cloud Blog
May 1, 2026 - In this article, we explored how to filter for a list of values in a pandas dataframe using the loc function. We demonstrated how to use the isin method to filter based on a list of values in one column and how to combine multiple conditions ...
Educative
educative.io › answers › how-to-filter-pandas-dataframe-by-column-value
How to filter pandas DataFrame by column value
isin() method: We can filter rows of a DataFrame based on whether the values in a specified column are present in a given list or array. ... To learn how we can apply a filter on the column values, let's first create a data example.
CodeRivers
coderivers.org › blog › python-dataframe-filter-column-value-in-list
Python DataFrame: Filtering Column Values in a List - CodeRivers
February 22, 2026 - By indexing the DataFrame with this mask (df[df['City'].isin(cities_list)]), we get the filtered DataFrame that only contains rows where the City value is either New York or Sydney. Boolean indexing can also be used to achieve the same result. We can create a boolean condition by comparing each value in the column with the values in the list element-by-element. import pandas as pd data = { 'Name': ['Alice', 'Bob', 'Charlie', 'David', 'Eve'], 'Age': [25, 30, 35, 40, 45], 'City': ['New York', 'London', 'Paris', 'New York', 'Sydney'] } df = pd.DataFrame(data) cities_list = ['New York', 'Sydney'] mask = False for city in cities_list: mask = mask | (df['City'] == city) filtered_df = df[mask] print(filtered_df)
GeeksforGeeks
geeksforgeeks.org › pandas › ways-to-filter-pandas-dataframe-by-column-values
Filter Pandas Dataframe by Column Value - GeeksforGeeks
July 15, 2025 - This code filters the DataFrame to include only rows where the "Age" column has values of either 25 or 45. The .query() method allows you to filter a DataFrame using SQL-like syntax. This can be particularly useful when dealing with complex conditions. ... import pandas as pd data = {'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 32,45], 'Score': [85, 90, 78]} df = pd.DataFrame(data) # Filter using query method where Age > 30 and Score < 90 filtered_df = df.query('Age > 30 and Score < 90') print(filtered_df)
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.filter.html
pandas.DataFrame.filter — pandas 3.0.6 documentation
>>> # select columns by name >>> df.filter(items=["one", "three"]) one three mouse 1 3 rabbit 4 6
Arab Psychology
scales.arabpsychology.com › home › how do i filter rows of a pandas dataframe by column value?
How Do I Filter Rows Of A Pandas DataFrame By Column Value?
November 22, 2025 - Instead of writing cumbersome logical OR statements, you supply a list or series of target values, and pandas handles the comparison across the entire selected column. This results in cleaner code, improved readability, and significantly faster execution times when dealing with large-scale DataFrame operations. This guide will explore the mechanics of using isin() to filter rows in a DataFrame.
Medium
deallen7.medium.com › using-pandas-loc-and-isin-to-filter-for-a-list-of-values-in-python-a1c862054058
Using Pandas’ .loc and .isin() to Filter for a List of Values in Python | by David Allen | Medium
July 26, 2022 - Image by 95C from Pixabay · Member-only story · Data Science · Data · Python · Pandas · David Allen · 2 min read · ·Jul 19, 2021 · -- 1 · Listen · Share · I use .loc on a daily basis. It’s like using the filter function on a spreadsheet. It’s an effortless way to filter down a Pandas Dataframe into a smaller chunk of data. It typically works like this: new_df = df.loc[df.column == 'value'] Sometimes, you’ll want to filter by a couple of conditions.
Statology
statology.org › home › how to filter a pandas dataframe by column values
How to Filter a Pandas DataFrame by Column Values
March 11, 2021 - The following code shows how to filter the rows of the DataFrame based on values in a list · #define list of values value_list = [12, 19, 25] #return rows where points is in the list of values df.query('points in @value_list') team points assists rebounds 0 A 25 5 11 1 A 12 7 8 4 C 19 12 6 #return rows where points is not in the list of values df.query('points not in @value_list') team points assists rebounds 2 B 15 7 10 3 B 14 9 6 · How to Replace Values in Pandas How to Drop Rows with NaN Values in Pandas How to Drop Duplicate Rows in Pandas
Pandas
pandas.pydata.org › docs › getting_started › intro_tutorials › 03_subset_data.html
How do I select a subset of a DataFrame? — pandas 3.0.6 documentation
Fare Cabin Embarked 0 1 0 3 ... 7.2500 NaN S 1 2 1 1 ... 71.2833 C85 C 2 3 1 3 ... 7.9250 NaN S 3 4 1 1 ... 53.1000 C123 S 4 5 0 3 ... 8.0500 NaN S [5 rows x 12 columns] The notna() conditional function returns a True for each row the values are not a Null value. As such, this can be combined with the selection brackets [] to filter the data table.
Built In
builtin.com › data-science › pandas-filter
How to Filter Pandas DataFrames | Built In
We’ve now selected the rows in which the value in the “val” column is greater than 0.5. The logical operators function also works on strings. f[df.name > 'Jane'] name ctg val val2 ------------------------------------------- 1 John A 0.67 1 3 Mike B 0.91 5 · Only the names that come after “Jane” in alphabetical order are selected. Pandas allows for combining multiple logical operators.