use loc indexer and give value

df.loc[df['column A'] == 2, ['column B', 'column C']] = [4, 8]

output(df):

    column A    column B    column C
0   1           NaN         NaN
1   1           NaN         NaN
2   1           NaN         NaN
3   2           4.0         8.0
4   2           4.0         8.0
5   2           4.0         8.0
6   3           NaN         NaN
7   3           NaN         NaN
8   3           NaN         NaN
Answer from Panda Kim on Stack Overflow
🌐
GitHub
gist.github.com › BenjaminWolfe › 50b272da0c30431e72ff7273190221ae
How do I use np.where with multiple columns at once? · GitHub
How do I use np.where with multiple columns at once? Raw · np-where-multiple-columns.py · This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
🌐
Python Guides
pythonguides.com › python-numpy-where
Optimizing Data Analysis in Pandas Using np.where() in 2025
May 16, 2025 - In this example, I’ve used np.where() to create a new column called ‘Performance’ that labels each state as either ‘High’ or ‘Regular’ based on their sales figures. Check out Replace Values in NumPy Array by Index in Python · Sometimes you need more than just a binary True/False condition. Here’s how to handle multiple conditions: import pandas as pd import numpy as np # Sample DataFrame of US cities and temperatures data = { 'City': ['Phoenix', 'Chicago', 'Miami', 'Seattle', 'Denver'], 'Temp_F': [105, 45, 85, 60, 75] } df = pd.DataFrame(data) # First condition df['Weather'] = np.where(df['Temp_F'] > 90, 'Hot', np.where(df['Temp_F'] < 50, 'Cold', 'Moderate')) print(df)
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.where.html
pandas.DataFrame.where — pandas 3.0.6 documentation
>>> df = pd.DataFrame(np.arange(10).reshape(-1, 2), columns=["A", "B"]) >>> df A B 0 0 1 1 2 3 2 4 5 3 6 7 4 8 9 >>> m = df % 3 == 0 >>> df.where(m, -df) A B 0 0 -1 1 -2 3 2 -4 -5 3 6 -7 4 -8 9 >>> df.where(m, -df) == np.where(m, df, -df) A B 0 True True 1 True True 2 True True 3 True True 4 True True >>> df.where(m, -df) == df.mask(~m, -df) A B 0 True True 1 True True 2 True True 3 True True 4 True True
🌐
IncludeHelp
includehelp.com › python › numpy-where-function-multiple-conditions.aspx
Python - NumPy 'where' function multiple conditions
We will then make a new column by traversing all the percentages and giving them their corresponding divisions according to the condition. To tackle the problem of comparing two conditions only, we check the value with np.where() condition to check all the three conditions and assign the values to them. ... # Importing pandas package import pandas as pd # Import numpy package import numpy as np # Creating a Dictionary d = {'Percentage':[45,56,78,98,76,88,76,43,54,67,54,77,67,98,59]} # Creating a DataFrame df = pd.DataFrame(d) # Display Original DataFrame print("Created DataFrame 1:\n",df,"\n")
Find elsewhere
🌐
Arab Psychology
scales.arabpsychology.com › home › how to create new column using multiple if else conditions in pandas
How To Create New Column Using Multiple If Else Conditions In Pandas
November 23, 2025 - Pandas can be used to create new columns using multiple if else conditions by using the 'np.where()' function. This function takes three arguments: a boolean
🌐
Stack Overflow
stackoverflow.com › questions › 68825113 › pandas-np-where-or-np-select-generate-multiple-columns-in-1-line-code
python - Pandas np.where or np.select generate multiple columns in 1 line code - Stack Overflow
August 17, 2021 - condition = df['RB'].eq(46) # Some more interesting condition than True df[['RB', 'Valindex0']] = np.where( np.tile(condition.values[:, None], 2), # Make condition match DataFrame columns df[['RB', 'Valindex0']], None ) ... contract RB BeginDate ValIssueDate EndDate Valindex0 0 A00118 46 19000100 19880901 19841231 50 1 A00118 46 19850100 19880901 99999999 50 2 A00118 None 19000100 19880901 19831231 None 3 A00118 None 19840100 19880901 19841299 None · Multiple conditions can be done as well by creating a structure that is of the correct shape (like another DataFrame):
🌐
GeeksforGeeks
geeksforgeeks.org › python › how-to-use-numpy-where-with-multiple-conditions-in-python
How to use NumPy where() with multiple conditions in Python ? - GeeksforGeeks
July 23, 2025 - Numpy where() with multiple conditions using logical OR. ... # Import NumPy library import numpy as np # Create an array using the list np_arr1 = np.array([23, 11, 45, 43, 60, 18, 33, 71, 52, 38]) print("The values of the input array :\n", np_arr1) # Create another array based on the # multiple conditions and one array new_arr1 = np.where((np_arr1)) # Print the new array print("The filtered values of the array :\n", new_arr1) # Create an array using range values np_arr2 = np.arange(40, 50) # Create another array based on the # multiple conditions and two arrays new_arr2 = np.where((np_arr1), np_arr1, np_arr2) # Print the new array print("The filtered values of the array :\n", new_arr2)
🌐
Medium
medium.com › @kelvinsang97 › python-np-where-97bdbdcf9eab
Python np.where(). This function can be used to select… | by Kelvin Kipsang | Medium
February 9, 2023 - Now we begin applying the np.where() function to categorizing column values into atmost two unique row values.
🌐
Statology
statology.org › home › how to use numpy where() with multiple conditions
How to Use NumPy where() With Multiple Conditions
November 9, 2021 - import numpy as np #define NumPy array of values x = np.array([1, 3, 3, 6, 7, 9, 12, 13, 15, 18, 20, 22]) #select values that meet two conditions x[np.where((x > 5) & (x < 20))] array([6, 7, 9, 12, 13, 15, 18])
🌐
Statology
statology.org › home › pandas: how to use equivalent of np.where()
Pandas: How to Use Equivalent of np.where()
June 24, 2022 - x = np.where(condition, value_if_true, value_if_false) And here’s the basic syntax using the pandas where() function:
🌐
GeeksforGeeks
geeksforgeeks.org › filter-pandas-dataframe-with-multiple-conditions
Filter Pandas Dataframe with multiple conditions - GeeksforGeeks
August 7, 2024 - Output resolves for the given conditions and finally, we are going to show only 2 columns namely Name and JOB. Here will get all rows having Salary greater or equal to 100000 and Age < 40 and their JOB starts with ‘D’ from the data frame. We need to use NumPy. ... # import module import pandas as pd import numpy as np # assign data dataFrame = pd.DataFrame({'Name': [' RACHEL ', ' MONICA ', ' PHOEBE ', ' ROSS ', 'CHANDLER', ' JOEY '], 'Age': [30, 35, 37, 33, 34, 30], 'Salary': [100000, 93000, 88000, 120000, 94000, 95000], 'JOB': ['DESIGNER', 'CHEF', 'MASUS', 'PALENTOLOGY', 'IT', 'ARTIST']}) # filter dataframe filtered_values = np.where((dataFrame['Salary']>=100000) & (dataFrame['Age']< 40) & (dataFrame['JOB'].str.startswith('D'))) print(filtered_values) display(dataFrame.loc[filtered_values])
🌐
Medium
medium.com › @michalwesleymnach › the-complete-guide-to-create-columns-based-on-multiple-conditions-in-pandas-dataframes-eedf2c0392a6
The complete guide to creating columns based on multiple conditions in a Pandas DataFrame | by Michaël Ménaché | Medium
July 17, 2022 - don’t need to repeat the name of the column to create for each condition · still very efficient when using np.vectorize() Cons: doesn’t allow nested conditions · .loc[] is usually one of the first things taught about Pandas and is traditionally used to select rows and columns.