pandas 检查数据框是否具有零元素

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/50767452/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-14 05:40:22  来源:igfitidea点击:

Check if dataframe has a zero element

pythonpandasdataframe

提问by Victor

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

在Pandas数据框中,检查至少一个元素是否为 0 的最快方法是什么?想象一下数据是:

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

我需要返回 true,因为至少有一个元素是 0。整个数据框中有一个元素,而不是每行/列一个元素

采纳答案by YOBEN_S

Maybe using anytwice

也许使用any两次

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

回答by Joe

You can do in this way:

你可以这样做:

 0 in df.values

回答by harvpan

You can use isin:

您可以使用isin

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