Another option with DataFrame.where():

df[['C1', 'V1']].where(df.Cond == "X", df[['C2', 'V2']].values)

#  C1   V1
#0  1    2
#1  7    8
#2  9   10
Answer from akuiper on Stack Overflow
๐ŸŒ
Net Informations
net-informations.com โ€บ ds โ€บ pd โ€บ mcolumns.htm
Selecting multiple columns in a Pandas dataframe based on condition
This function is particularly useful for filtering data based on specific criteria and identifying rows that match certain conditions. ... The isin() method in Pandas enables the selection of multiple columns from a DataFrame based on specific conditional values.
๐ŸŒ
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 ... ... 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]) ...
๐ŸŒ
Spark By {Examples}
sparkbyexamples.com โ€บ home โ€บ pandas โ€บ select pandas columns based on condition
Select Pandas Columns Based on Condition - Spark By {Examples}
June 27, 2025 - We can select columns based on single/multiple conditions using the pandas loc[] attribute. The DataFrame.loc[] attribute property is used to select rows
๐ŸŒ
KeyToDataScience
keytodatascience.com โ€บ data science โ€บ selecting rows and columns based on conditions in python pandas dataframe
Selecting Rows and Columns Based on Conditions in Python Pandas DataFrame - KeyToDataScience
January 16, 2022 - The iloc syntax is data.iloc[<row selection>, <column selection>]. โ€œilocโ€ in pandas is used to select rows and columns by number, in the order that they appear in the DataFrame. Both row and column numbers start from 0 in python. # rows df.iloc[0] # first row of data frame (Sam) df.iloc[-1] ...
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python โ€บ pandas
pandas: Select rows by multiple conditions | note.nkmk.me
August 8, 2023 - When working with three or more conditions, the outcome can vary based on their order.
๐ŸŒ
thisPointer
thispointer.com โ€บ home โ€บ pandas โ€บ pandas โ€“ select rows by conditions on multiple columns
Pandas - Select Rows by conditions on multiple columns - thisPointer
February 12, 2023 - import pandas as pd def main(): # List of Tuples students = [ ('jack', 'Apples' , 34) , ('Riti', 'Mangos' , 31) , ('Aadi', 'Grapes' , 30) , ('Sonia', 'Apples', 32) , ('Lucy', 'Mangos' , 33) , ('Mike', 'Apples' , 35) ] #Create a DataFrame object dfObj = pd.DataFrame(students, columns = ['Name' , 'Product', 'Sale']) print("Original Dataframe" , dfObj, sep='\n') ''' Select Rows based on value in a column ''' subsetDataFrame = dfObj[dfObj['Product'] == 'Apples'] print("DataFrame with Product : Apples" , subsetDataFrame, sep='\n') filteringSeries = dfObj['Product'] == 'Apples' print("Filtering Seri
Find elsewhere
๐ŸŒ
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 - To filter rows based on multiple conditions, we can use the & (and) and | (or) operators to combine multiple conditions. For example, letโ€™s say we have a dataframe df with columns A, B, and C. We want to select all rows where A is greater ...
๐ŸŒ
Statology
statology.org โ€บ home โ€บ pandas: how to select columns based on condition
Pandas: How to Select Columns Based on Condition
November 4, 2022 - You can use the following methods to select columns in a pandas DataFrame by condition: Method 1: Select Columns Where At Least One Row Meets Condition ยท #select columns where at least one row has a value greater than 2 df.loc[:, (df > 2).any()] ...
๐ŸŒ
Medium
imaadmkhan1.medium.com โ€บ using-pandas-to-create-a-conditional-column-by-selecting-multiple-columns-in-two-different-b50886fabb7d
Using Pandas to create a conditional column by selecting multiple columns in two different dataframes | by Imaad Mohamed Khan | Medium
May 12, 2018 - Letโ€™s suppose that one product is delivered in one batch. This batch information has been stored in another table. In this case, the data for the batches can be represented in another dataframe as below: ... Great! So now our task is to get batch ids from the second dataframe and append it as a new column to the first dataframe provided certain conditions are fulfilled. Here we want to append batch ids based on two conditions.
๐ŸŒ
Pandas
pandas.pydata.org โ€บ pandas-docs โ€บ stable โ€บ getting_started โ€บ intro_tutorials โ€บ 03_subset_data.html
How do I select a subset of a DataFrame? โ€” pandas 3.0.5 documentation
Fare Cabin Embarked 1 2 1 1 ... 71.2833 C85 C 6 7 0 1 ... 51.8625 E46 S 11 12 1 1 ... 26.5500 C103 S 13 14 0 3 ... 31.2750 NaN S 15 16 1 2 ... 16.0000 NaN S [5 rows x 12 columns] To select rows based on a conditional expression, use a condition inside the selection brackets [].
๐ŸŒ
Saturn Cloud
saturncloud.io โ€บ blog โ€บ pandas-selecting-multiple-columns-from-one-row
Pandas: Selecting Multiple Columns from One Row | Saturn Cloud Blog
May 1, 2026 - Here, we first use the loc method to select the row where Name is โ€˜Aliceโ€™. We do this by specifying the condition df['Name'] == 'Alice' inside the loc method. Next, we specify a list of column names that we want to select from this row.
๐ŸŒ
Codepointtech
codepointtech.com โ€บ home โ€บ how to select columns based on condition in pandas
How to Select Columns Based on Condition in Pandas - codepointtech.com
January 17, 2026 - One of the most common conditions for column selection is their data type. Pandas provides the convenient select_dtypes() method for this purpose.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ selecting-rows-in-pandas-dataframe-based-on-conditions
Selecting rows in pandas DataFrame based on conditions - GeeksforGeeks
August 7, 2024 - In this article, we will learn how to select the limited rows with given columns with the help of these methods. Example 1: Select two columns Python3 # Import pandas package import pandas as pd # Defi ยท 2 min read Drop rows from dataframe based on certain condition applied on a column - Pandas