how to check whether ALL elements in a Pandas series are equal to a specific value

六眼飞鱼酱① 提交于 2020-06-23 04:08:22

问题


For a given series, e.g.

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

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.

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


回答1:


You should use the following syntax:

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

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



回答2:


Another way to do the same would be:

print((s==0).all())


来源:https://stackoverflow.com/questions/58359706/how-to-check-whether-all-elements-in-a-pandas-series-are-equal-to-a-specific-val

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!