比较列值熊猫

危机

我有两列,我像这样创建:

df_o['a'] = (df['sell'] == 1).resample(interval).sum().astype(int)
df_o['b'] = (df['sell'] == 0).resample(interval).sum().astype(int)

我希望计算这两列之间的比率,即:

df_o['ratioab'] = df_o['a'] / df_o['b']

这有效,但我找不到避免x/00/x对于熊猫等于 Inf 的方法。我想设置这种情况df_o['ratioab'] = 0

这不起作用:

if (0 == df_o['a']).all() | (0 == df_o['b']).all():
    df_ohlc['ratioab'] = 0
耶斯列

一种可能的解决方案是:

df_o['ratioab'] = (df_o['a'] / df_o['b']).replace(np.inf, 0)

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章