我有一个由三列组成的数据帧
qty unit_of_measure qty_cal
3 nodes nan
4 nodes nan
5 nodes nan
6 cores nan
7 nodes nan
10 cores nan
3 nodes nan
我想添加一个条件来填充数量\u cal。你知道吗
条件是如果度量单位等于“节点”,则将qty的行值填充到qty\u cal中
如果是“cores”,则将qty值除以16并填充qty\u cal
我试过的密码是
if ppn_df['unit_of_measure'] == 'Nodes':
ppn_df['qty']
elif ppn_df['unit_of_measure'] =='Cores':
ppn_df['qty'] / 16
我犯了个错误
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
我不知道为什么会出现这个值错误。我不明白为什么if语句模棱两可。你知道吗
有人愿意解释一下吗?你知道吗
使用
np.where
:语句
ppn_df['unit_of_measure']
返回一个包含所有值的序列(一列),而不是单个项。一种方法是使用apply
或map
试试这个
此函数将为序列中的每一行执行
lambda
函数相关问题 更多 >
编程相关推荐