Skip to content
Advertisement

I’m trying to use multiple nested np.where to create a column of a data frame in python ,facing error on the same

Consider a data frame with 97 rows and 44 columns where i have three columns whose names are “Bostwick”,”mu_yield” , so i’m trying to create a new column called “Target” where if the “Bostwick” column values lie between “5.00 and 6.75” else if “mu_yield” column values lie between “89.00 and 90.00” , the “Target” column values should be 0 else it is 1

I tried the below way

JavaScript

There were no errors but the entire “Target” column values are 0

Hence i tried the below method

JavaScript

Here i’m facing the below value error

JavaScript

Requesting someone to help me on the same

Advertisement

Answer

Use | for bitwise OR and in original use & for bitwise AND:

JavaScript

Alternative with Series.between:

JavaScript
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement