我需要根据熊猫数据框中另一列的值来设置一列的值。这就是逻辑:
if df['c1'] == 'Value':
df['c2'] = 10
else:
df['c2'] = df['c3']
I am unable to get this to do what I want, which is to simply create a column with new values (or change the value of an existing column: either one works for me).
如果我尝试运行上面的代码,或者将其作为函数编写并使用 application 方法,我会得到以下结果:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().