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
>>> # select columns by regular expression >>> df.filter(regex="e$", axis=1) one three mouse 1 3 rabbit 4 6
🌐
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 2 3 1 3 ... 7.9250 NaN S 4 5 0 3 ... 8.0500 NaN S 5 6 0 3 ... 8.4583 NaN Q 7 8 0 3 ... 21.0750 NaN S [5 rows x 12 columns] Similar to the conditional expression, the isin() conditional function returns a True for each row the values are in the provided list. To filter the rows based on such a function, use the conditional function inside the selection brackets []. In this case, the condition inside the selection brackets titanic["Pclass"].isin([2, 3]) checks for which rows the Pclass column is either 2 or 3.
🌐
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)
🌐
Note.nkmk.me
note.nkmk.me › home › python › pandas
pandas: Filter rows/columns by labels with filter() | note.nkmk.me
January 24, 2024 - In pandas, use the filter() method to select rows or columns in the DataFrame based on their labels (names). This method is provided for both DataFrame and Series. pandas.DataFrame.filter — pandas 2. ...
🌐
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 - df.filter(regex='^S', axis=1) # ... numeric columns or all categorical columns.” · pandas’ .select_dtypes() helps you filter columns based on their data type....
🌐
Towards Data Science
towardsdatascience.com › home › latest › 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 21, 2026 - Pandas is an excellent library for data manipulation and retrieval. Combine it with Numpy and Seaborne, and you’ve got yourself a powerhouse for data analysis. In this article, I’ll be walking you through practical ways to filter data in pandas, starting with simple conditions and moving on to powerful methods like .isin(), .str.startswith(), and .query().
🌐
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.
🌐
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 - Filtering is pretty candid here. You pick the column and match it with the value you want. A common confusion when it comes to filtering in Pandas is the use of conditional operators.
🌐
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.