如何在包含pandas数据帧的两列的控制语句中添加逻辑AND
,即
这是有效的:
def getContinent(row):
if row['Location'] in ['US','Canada']:
val = 'North America'
elif row['Location'] in['UK', 'Germany']:
val = 'Europe'
else:
val = None
return val
df.apply(getContinent, axis=1)
现在我想在另一个字段row['Sales']
中包含一个附加条件:
ValueError: ('Arrays were different lengths: 6132 vs 2', u'occurred at index 0')
您需要使用
and
代替&
:相关问题 更多 >
编程相关推荐