Just pass a list of column names to index df:

df[['nnn', 'mmm', 'yyy']]

   nnn  mmm  yyy
0    5    5   10
1    3    4    9
2    7    0    8

If you need to handle non-existent column names in your list, try filtering with df.columns.isin -

df.loc[:, df.columns.isin(['nnn', 'mmm', 'yyy', 'zzzzzz'])]

   yyy  nnn  mmm
0   10    5    5
1    9    3    4
2    8    7    0
Answer from coldspeed95 on Stack Overflow
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.filter.html
pandas.DataFrame.filter — pandas 3.0.6 documentation
The filtered subset of the DataFrame or Series. ... Access a group of rows and columns by label(s) or a boolean array.
🌐
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
To select a single column, use square brackets [] with the column name of the column of interest. For more explanation, see Brackets in Python and pandas.
🌐
GeeksforGeeks
geeksforgeeks.org › pandas › ways-to-filter-pandas-dataframe-by-column-values
Filter Pandas Dataframe by Column Value - GeeksforGeeks
July 15, 2025 - The .loc[] method allows for more complex filtering, used to filter both rows and columns at the same time by specifying conditions for both axes. It allows to specify conditions directly within the square brackets. ... import pandas as pd data = {'Name': ['Alice', 'Bob', 'Charlie'], 'Age': [25, 32,45], 'Score': [85, 90, 78]} df = pd.DataFrame(data) # Filter rows where Age > 30 and select only 'Name' and 'Score' columns filtered_df = df.loc[df['Age'] > 30, ['Name', 'Score']] print(filtered_df)
🌐
Medium
deallen7.medium.com › using-pandas-contains-method-to-filter-a-dataframe-column-for-specific-words-or-phrases-7567e7dcebb8
Using Pandas’ contains() method to filter a DataFrame column for specific words or phrases | by David Allen | Medium
July 26, 2022 - If you have ever analyzed text data in an Excel Spreadsheet or a Google Sheet, you’re familiar with the task of filtering a column of text for a word or phrase. Pandas’ contains() method gives you this same ability for any column of string values in a Pandas DataFrame.
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Filter rows/columns by labels with filter() | note.nkmk.me
January 24, 2024 - You can specify the axis to filter on with the axis argument. Use 0 or 'index' for rows and 1 or 'columns' for columns.
🌐
SheCanCode
shecancode.io › home › news & articles › filter a dataframe by partial string or pattern
Filter a DataFrame by Partial String or Pattern - SheCanCode
March 4, 2025 - As a data professional, chances are you will often need to separate data based on its contents. In this article, we looked at 8 ways to filter a DataFrame by the string values present in the columns. We used Pandas, Lambda functions, and the ‘in’ keyword.
Find elsewhere
🌐
Medium
medium.com › @heyamit10 › how-to-filter-columns-based-on-conditions-5f4c41dac45b
How to Filter Columns Based on Conditions? | by Hey Amit | Medium
March 6, 2025 - “What if you need to grab columns that follow a pattern — maybe all columns that start with ‘S’ or contain a certain word?” · pandas’ .filter() lets you do exactly that.
🌐
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 - Pandas enables us to filter on multiple conditions using logical operators. However, these operators are different from Python's built-in operators like (and, or, not). Here are the logical operators you’ll be working with the most · The ampersand (&) symbol represents AND in pandas.
🌐
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.
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas filter by column value
Pandas Filter by Column Value - Spark By {Examples}
June 6, 2025 - Pandas support several ways to filter by column value, DataFrame.query() function is the most used to filter rows based on a specified expression,
🌐
Medium
medium.com › swlh › 3-ways-to-filter-pandas-dataframe-by-column-values-dfb6609b31de
3 ways to filter Pandas DataFrame by column values | by Padhma Muniraj | The Startup | Medium
February 15, 2022 - Inside .loc , the condition within the parentheses evaluates to a boolean value which is then applied upon the column specified. The data returned from multiple filters depends on the operation performed. When & and | operations are performed without an assignment, a series is returned.
🌐
YoungWonks
youngwonks.com › blog › top-10-ways-to-filter-pandas-dataframe
What is pandas and a pandas dataframe? What are the top 10 ways to filter pandas dataframe? Read our blog to learn more...
June 17, 2022 - Therefore, it is important to know these commands in order to use them effectively. In this python tutorial, we are going to learn the top 10 ways to filter pandas dataframe. Making use of specific column names from the dataset, we can choose multiple columns from a pandas dataframe.
🌐
W3Schools
w3schools.com › python › pandas › ref_df_filter.asp
Pandas DataFrame filter() Method
Return a DataFrame with only the "name" and "age" columns: import pandas as pd data = { "name": ["Sally", "Mary", "John"], "age": [50, 40, 30], "qualified": [True, False, False] } df = pd.DataFrame(data) newdf = df.filter(items=["name", "age"]) Try it Yourself » ·
🌐
Saturn Cloud
saturncloud.io › blog › how-to-filter-pandas-dataframes-by-column-of-strings
How to Filter Pandas DataFrames by Column of Strings | Saturn Cloud Blog
May 1, 2026 - The str attribute provides a set of string methods that can be used to filter, search, and manipulate strings in a DataFrame column.
🌐
Analytics Vidhya
analyticsvidhya.com › home › ways to filter pandas dataframe by column values
Ways to Filter Pandas DataFrame by Column Values
May 1, 2025 - Pandas supports filtering using regular expressions. We can filter rows by using the “str.contains” method with a regular expression pattern. Here’s an example: ... We can define custom functions to filter a DataFrame based on specific ...
🌐
YouTube
youtube.com › watch
Filtering Columns and Rows in Pandas | Python Pandas ...
Enjoy the videos and music you love, upload original content, and share it all with friends, family, and the world on YouTube.
🌐
Vultr Docs
docs.vultr.com › python › third-party › pandas › DataFrame › filter
Python Pandas DataFrame filter() - Filter Data Rows | Vultr Docs
December 25, 2024 - While filter() is predominantly used to select specific DataFrame columns, combining it with techniques like boolean indexing, regex, and conditional filters allows for flexible and powerful row filtrations.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-filter-pandas-dataframe-with-specific-column-names-in-python
How to Filter Pandas DataFrame with Specific Column Names in Python | Saturn Cloud Blog
May 1, 2026 - For example, you may want to filter a DataFrame to only include specific columns that are relevant to your analysis. One of the most straightforward methods to filter a Pandas DataFrame is by using square brackets to select columns of interest.