检查大熊猫在相同条件下的多列的更好方法?


9

我得到了输出,但是试图找到一种更有效的方法来做到这一点:

(df['budget'] == 0).sum(), (df['revenue'] == 0).sum(),(df['budget_adj'] == 0).sum(), (df['revenue_adj'] == 0).sum()

输出是

(5674, 5993, 5676, 5993)

2
df[['budget', 'revenue', 'budget_adj', 'revenue_adj']].eq(0).sum()
Erfan

Answers:


4

您可以批量比较各列,并按列进行汇总:

(df[['budget', 'revenue', 'budget_adj', 'revenue_adj']] == 0).sum(axis=0)

谢谢!那就是我想要的
Ankvis
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.