I think using functions here is unnecessary. It is better and mainly faster to use boolean indexing:

m = (df['Name'] == 'Alisa') & (df['Age'] > 24)
print(m)
0      True
1     False
2     False
3     False
4     False
5     False
6      True
7     False
8     False
9     False
10    False
11    False
dtype: bool

#invert mask by ~
df1 = df[~m]

For more complicated filtering, you could use a function which must return a boolean value:

def filter_fn(row):
    if row['Name'] == 'Alisa' and row['Age'] > 24:
        return False
    else:
        return True

df = pd.DataFrame(d, columns=['Name', 'Age', 'Score'])
m = df.apply(filter_fn, axis=1)
print(m)
0     False
1      True
2      True
3      True
4      True
5      True
6     False
7      True
8      True
9      True
10     True
11     True
dtype: bool

df1 = df[m]
Answer from jezrael on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.filter.html
pandas.DataFrame.filter — pandas 3.0.6 documentation
For DataFrame, filter rows or columns depending on axis argument. Note that this routine does not filter based on content.
🌐
ListenData
listendata.com › home › pandas
Python : 10 Ways to Filter Pandas DataFrame
Let's prepare a fake data for example. ... first letter. ... Filter rows having string length greater than 3 len( ) function calculates length of iterable....
🌐
Python Examples
pythonexamples.org › pandas-dataframe-filter-rows
Pandas DataFrame - Filter Rows
To filter rows of Pandas DataFrame, you can use DataFrame.isin() function or DataFrame.query(). isin() can be used to filter the DataFrame rows based on the exact match of the column values or being in a range. query() can be used with a boolean expression, where you can filter the rows based ...
🌐
Built In
builtin.com › data-science › pandas-filter
How to Filter Pandas DataFrames | Built In
Filtering in Pandas means to subset (or display) certain rows and columns in a Pandas DataFrame based on specified conditions. The dataframe.filter() function is one method of filtering a DataFrame in Pandas. Lines, or rows, in a Pandas DataFrame ...
🌐
w3resource
w3resource.com › pandas › dataframe › dataframe-filter.php
Pandas DataFrame: - filter() function - w3resource
Pandas DataFrame - filter() function: The filter() function is used to subset rows or columns of dataframe according to labels in the specified index.
🌐
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
Find elsewhere
🌐
HubSpot
blog.hubspot.com › home › the hubspot website blog
The HubSpot Website Blog
October 3, 2022 - HubSpot’s Website Blog covers everything you need to know to build maintain your company’s website.
🌐
Vultr Docs
docs.vultr.com › python › third-party › pandas › DataFrame › filter
Python Pandas DataFrame filter() - Filter Data Rows | Vultr Docs
December 25, 2024 - To filter rows based on conditions, consider combining filter() with boolean indexing or other functions like query(). ... This code filters the DataFrame to only include rows where the age is greater than 19.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas dataframe filter() – usage & examples
Pandas DataFrame filter() - Usage & Examples - Spark By {Examples}
June 27, 2025 - Pandas filter() function in Python is used the filters the DataFame rows and columns. The returned DataFrame contains only rows and columns that are
🌐
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
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.
🌐
Towards Data Science
towardsdatascience.com › home › latest › filtering pandas dataframe by objects’ content
Filtering Pandas Dataframe by objects' content | Towards Data Science
March 5, 2025 - The apply function iterates over rows (determined by the axis=1 parameter), represented by Series object, and maps a unary function to each. Essentially what a map function would do on a list.
🌐
W3Schools
w3schools.com › python › pandas › ref_df_filter.asp
Pandas DataFrame filter() Method
import pandas as pd data = { "name": ... "age"]) Try it Yourself » · The filter() method filters the DataFrame, and returns only the rows or columns that are specified in the filter....
🌐
Medium
medium.com › @epythonlab › top-10-pandas-functions-to-filter-data-like-a-pro-step-by-step-guide-536ac28cac7a
Top 10 Pandas Functions to Filter Data Like a Pro (Step-by-Step Guide) | by Epython Lab | Medium
September 10, 2024 - In this guide, I will dive deep into the top 10 pandas functions for filtering data effectively, with simple examples to help you understand and apply them to your projects. ... The loc[] function is ideal when filtering your data by specific ...
🌐
GeeksforGeeks
geeksforgeeks.org › python-pandas-dataframe-filter
Python | Pandas dataframe.filter() | GeeksforGeeks
November 19, 2018 - Python is a great language for ... importing and analyzing data much easier. Pandas dataframe.filter() function is used to Subset rows or columns of dataframe ......
🌐
Towards Data Science
towardsdatascience.com › home › latest › data filtering in pandas
Data filtering in Pandas | Towards Data Science
March 5, 2025 - Then, the sequence of booleans is placed inside square brackets [], returning the rows associated with a True value. ... The most common way to filter a data frame according to the values of a single column is by using a comparison operator.