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]) ...
๐ŸŒ
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 - Select rows or columns in Pandas DataFrame based on various conditions using .loc, .iloc and conditional operators '>', '=', '!' With Examples and Code.
๐ŸŒ
Note.nkmk.me
note.nkmk.me โ€บ home โ€บ python โ€บ pandas
pandas: Select rows by multiple conditions | note.nkmk.me
August 8, 2023 - pandas: Count values in DataFrame/Series with conditions ยท pandas: Replace values based on conditions with where(), mask()
๐ŸŒ
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
๐ŸŒ
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 - We will cover the following topics: Using the loc method to filter rows based on multiple conditions ยท Using the query method to filter rows based on multiple conditions ยท Using boolean indexing to filter rows based on multiple conditions ...
๐ŸŒ
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 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]) ...
๐ŸŒ
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 - While operating on data, there could be instances where we would like to add a column based on some condition. There does not exist any library function to achieve this task directly, so we are going to see how we can achieve this goal. In this article, we will see how to create a Pandas dataframe c