我正在尝试向我的 DataFrame
添加一列,这是其他两列相除的结果,如下所示:
df['$/hour'] = df['$']/df['hours']
This works fine, but if the value in ['hours']
is less than 1
, then the ['$/hour']
value is greater than the value in ['$']
,这不是我想要的。
有没有办法控制操作,以便 if ['hours'] < 1
那么 df['$/hour'] = df['$']
?
原文由 Charon 发布,翻译遵循 CC BY-SA 4.0 许可协议
您可以使用
numpy.where
: