检查 pandas 列是否包含除零以外的其他值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/48570797/
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:07:26  来源:igfitidea点击:

Check if pandas column contains other values other than zero

pandas

提问by DevEx

I'm doing a complex calculation on a dataframe which is bound to throw exception if all values in the column is all zeros. How to do a quick check whether a column is full of zero? i.e. return Trueif column has other values other 0else False

我正在对数据框进行复杂的计算,如果列中的所有值都为零,则该数据框必然会引发异常。如何快速检查一列是否充满零?即返回True如果列有其他其他值0其他False

回答by PraveenB

you can do something like this:

你可以做这样的事情:

(df['col'] == 0).all()

(df['col'] == 0).all()

This will return True if all values are 0 otherwise it will return false

如果所有值都为 0,这将返回 True 否则它将返回 false