Python 检查熊猫系列是否至少有一项大于某个值
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/34148815/
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
Check if a pandas Series has at least one item greater than a value
提问by ChaimG
The following code will print True because the Series contains at least one element that is greater than 1. However, it seems a bit un-Pythonic. Is there a more Pythonic way to return True if a Series contains a number that is > a particular value?
以下代码将打印 True,因为该系列包含至少一个大于 1 的元素。但是,它似乎有点非 Pythonic。如果系列包含大于特定值的数字,是否有更 Pythonic 的方式返回 True?
import pandas as pd
s = pd.Series([0.5, 2])
print True in (s > 1)
True
真的
EDIT: Not only is the above answer un-Pythonic, it will sometimes return an incorrect result for some reason. For example:
编辑:上述答案不仅非 Pythonic,而且有时会由于某种原因返回不正确的结果。例如:
s = pd.Series([0.5])
print True in (s < 1)
False
错误的