Python: Why is np.where not working with two conditions?
问题 I have the following data frame: >>> import pandas as pd >>> import numpy as np >>> df_test = pd.DataFrame({'id': [100, 101, 102, 103, 104], 'drive': ['4WD', None, '4WD', None, '2WD']}) >>> print(df_test) id drive 0 100 4WD 1 101 None 2 102 4WD 3 103 None 4 104 2WD And I would like to make a new column is_4x4 , that would be equal to 0, when drive is None , or drive is 2WD . In other cases, I would like the column to be equal to 1. I am using the following code, but the result is not as I