【问题标题】:argument of type 'NoneType' is not iterable pandas“NoneType”类型的参数不是可迭代的 pandas
【发布时间】:2017-07-13 05:01:38
【问题描述】:

我有以下两个功能:

#To update the label1 if word is present with is_name
def update(data,word_lists, is_name):
 for wlist in word_lists:
    if check_keywords(data, wlist):
        return is_name
 return ''

#To check if Words are present in my Short_description field.
def check_keywords(data, words):
 cnt=0
 for word in words:
    if word in data:
        cnt+=1
 return cnt==len(words)

以下是我的数据格式:

Short_description, label1

这些是我的数据 ACE_2017 中的列。 我需要检查 Short_description 中的关键字并更新 label1

下面是我的更新命令:

#To check if "access request" or "request Access" is present in Short_description then it should update label1 with 'Access request'

ACE_2017.ix[ACE_2017['label1']=='','label1'] = ACE_2017[ACE_2017['label1']==''].Short_description.map(lambda x: update(x,[['access request','request Access']],'Access request'))

但是当我运行上面的命令时它说

“NoneType”类型的参数不可迭代

我在这里缺少什么,我该如何解决这个问题。

【问题讨论】:

  • 我写了一个答案,但它也有助于了解你想要做什么
  • 用数据及其目的更新了我的问题

标签: python pandas


【解决方案1】:

这个问题你很清楚。 “'NoneType' 类型的参数不可迭代”。在 python 中,如果你尝试遍历 None 类型的对象,那么问题就来了。

在您的情况下,除了“简短描述”列值之外,其他所有参数都已修复。每次迭代都会发生变化。检查“简短描述”列是否包含任何“NaN”值。!!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-01-07
    • 2011-10-04
    • 2016-04-06
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-04-15
    相关资源
    最近更新 更多