vectorize conditional assignment in pandas dataframe
One simple method would be to assign the default value first and then perform 2 loc calls: If you wanted to use np.where then you could do it with a nested np.where: So here we define the first condition as where x is less than -2, return 1, then we have another np.where which tests the other condition where x is greater … Read more