简体   繁体   English

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

[英]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.

相关问题 为什么我收到TypeError“类型'类型'的参数不可迭代”? - Why do i get the TypeError “argument of type 'type' is not iterable”? “float”类型的参数不可迭代 - TypeError - argument of type 'float' is not iterable - TypeError 类型错误:“float”类型的参数不可迭代 - TypeError: argument of type 'float' is not iterable Python Lambda:TypeError:“ float”类型的参数不可迭代 - Python lambda: TypeError: argument of type 'float' is not iterable 为什么我收到错误 TypeError:“名称”类型的参数不可迭代? - Why do I receive error TypeError: argument of type 'Name' is not iterable? Pandas.DataFrame.Apply-TypeError:类型'float'的参数不可迭代 - Pandas.DataFrame.Apply - TypeError: argument of type 'float' is not iterable TypeError:在 dataframe 中使用 lambda function 时,“float”类型的参数不可迭代 - TypeError: argument of type 'float' is not iterable when using lambda function in dataframe TypeError:'float' 类型的参数不可迭代 - 重塑 csv 文件 - TypeError: argument of type 'float' is not iterable - reshape csv file 当我将列表转换为字符串时,为什么这会给我“TypeError:'int' 类型的参数不可迭代” - Why is this giving me "TypeError: argument of type 'int' is not iterable" when I converted the list to strings Python - 'float' 类型的参数不可迭代 - Python - argument of type 'float' is not iterable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM