如何检查Pandas系列中的所有元素是否都等于特定值 [英] how to check whether ALL elements in a Pandas series are equal to a specific value

查看:202
本文介绍了如何检查Pandas系列中的所有元素是否都等于特定值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于给定的系列,例如

s = pd.Series([0,0,0])

我想检查此系列中的所有元素是否都等于一个特定值(在此示例中,我们可以使用0),如果是这种情况,则返回TRUE,否则返回FALSE.

I would like to check whether ALL elements in this series are equal to a specific value (we can use 0 in this example) and return TRUE if that is the case, and FALSE otherwise.

在Pandas/numpy中有方便的方法吗?

is there a handy way to do those in Pandas/numpy?

推荐答案

您应使用以下语法:

s = pd.Series([0,0,0])

print(s.eq(0).all())
True

这篇关于如何检查Pandas系列中的所有元素是否都等于特定值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆