Better way to check multiple columns with the same condition in pandas?

Ankvis :

I got the output but trying to find a more efficient way to do this:

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

Output is

(5674, 5993, 5676, 5993)
Willem Van Onsem :

You can compare the columns in bulk and sum these up column-wise:

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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=319201&siteId=1