Victor
Victor

Reputation: 17097

Check if dataframe has a zero element

In a pandas dataframe, what is the quickest way to check if at least one element is 0? Imagine the data is :

Name   Asset  Revenue
A       10     20
B       0      21

I need to return true because at least one element is 0. One element across the dataframe, not one element per row/column

Upvotes: 12

Views: 32665

Answers (3)

harpan
harpan

Reputation: 8631

You can use isin:

df.isin([0]).any().any()

Upvotes: 5

BENY
BENY

Reputation: 323226

Maybe using any twice

df.eq(0).any().any()
Out[173]: True

Upvotes: 10

Joe
Joe

Reputation: 12417

You can do in this way:

 0 in df.values

Upvotes: 11

Related Questions