我正在尝试根据两个现有列的条件创建一个新列,但是在使用“np.where”后出现错误,有没有其他方法可以实现这一点?
输入:
change1 change2
yes yes
yes no
no yes
no yes
预期输出:
change1 change2 change3
yes yes ok
yes no not ok
no yes not ok
no yes not ok
法典:
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)
错误:
cannot compare a dtyped [object] array with a scalar of type [bool]
一只斗牛犬
吃鸡游戏
蓝山帝景
相关分类