繁体   English   中英

为什么在包含字符串和 NaN 的系列中出现“TypeError:'float' 类型的参数不可迭代”?

[英]Why do get a "TypeError: argument of type 'float' is not iterable" on a series with strings and NaN?

对于包含字符串和 NaN 值的系列,为什么series.apply(not_happy)

其中 not_happy 定义为:

def not_happy(element):
    if 'subtring' in element:
        return True
    else:
        return False

给出错误"TypeError: argument of type 'float' is not iterable"

您在不是 str 类型的系列中应用函数的值之一,或者您可能有一些缺失值。

检查元素的数据类型。

def not_happy(element): if 'subtring' in str(element): return True else: return False

这将使您的元素字符串类型和工作。

暂无
暂无

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

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