I am trying to create a new column based on conditions from two existing columns, but getting an error after using "np.where", is there any other way to achieve this ?
Input:
change1 change2
yes yes
yes no
no yes
no yes
Expected Output:
change1 change2 change3
yes yes ok
yes no not ok
no yes not ok
no yes not ok
Code:
import pandas as pd
import numpy as np
df1=pd.read_csv('test2.txt',sep='\t')
df1['change1'] = df1['change1'].astype(str)
df1['change2'] = df1['change2'].astype(str)
df['change3'] = np.where(df1['change1']=='yes' & df1['change2'] == 'yes', 'ok', 'not ok')
print(df1)
Error:
cannot compare a dtyped [object] array with a scalar of type [bool]