[英]Why do get a "TypeError: argument of type 'float' is not iterable" on a series with strings and NaN?
For a series containing strings and NaN values, why does series.apply(not_happy)
对于包含字符串和 NaN 值的系列,为什么series.apply(not_happy)
where not_happy is defined by:其中 not_happy 定义为:
def not_happy(element):
if 'subtring' in element:
return True
else:
return False
gives the error "TypeError: argument of type 'float' is not iterable"
给出错误"TypeError: argument of type 'float' is not iterable"
One of the values in the series you're applying the funciton on in not of str type or probably you have some missing values.您在不是 str 类型的系列中应用函数的值之一,或者您可能有一些缺失值。
check the data type of your element.检查元素的数据类型。
def not_happy(element): if 'subtring' in str(element): return True else: return False def not_happy(element): if 'subtring' in str(element): return True else: return False
This will make your element string type and work.这将使您的元素字符串类型和工作。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.