繁体   English   中英

如何检查 DataFrame 列中是否存在元组值

[英]How to check if a tuple value exists in a DataFrame column

我在 DataFrame 中有一个列,它包含字符串或字符串元组。 我想检查该列中是否存在某个值元组。

s = pd.Series(['a', ('b', 'c', 'd')])

'a' in s.values

这将返回True 然而:

('b', 'c', 'd') in s.values

返回False ,带有警告: FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison FutureWarning: elementwise comparison failed; returning scalar instead, but in the future will perform elementwise comparison

我该如何解决这个问题?

干得好:

s = pd.Series(['a', ('b', 'c', 'd')])
def check_tuple(x, tuple_string="('b', 'c', 'd')"):
    if str(x).find(tuple_string)>=0:
        return True
s.apply(check_tuple)

获取您系列中对象的所有哈希值,并将其与您要查找的哈希值进行比较

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM