【发布时间】:2017-12-17 22:30:39
【问题描述】:
我正在使用以下代码创建一个新列,其值是基于我的 Python 数据框的其他两列中的值派生的。
# Create a list to store the data
MSP = []
for row in df_EVENT5_18['FLT']:
if df_EVENT5_18['FLT'].str.contains('1234') & df_EVENT5_18['AR'].str.contains('ABC1'):
MSP.append(29)
elif (df_EVENT5_18['FLT'].str.contains('1234')) & (df_EVENT5_18['AR'].str.contains('ABC2')):
MSP.append(25)
else:
MSP.append('')
# Create a new column from the list
df_EVENT5_18['MSP'] = MSP
当我运行上面的代码时,我得到以下错误:
ValueError:Series 的真值不明确。使用 a.empty、a.bool()、a.item()、a.any() 或 a.all()。
【问题讨论】:
标签: python pandas if-statement conditional ambiguous