类型错误:';列表';对象不能使用python3在级别级函数片段上调用
我似乎无法纠正这个错误。它曾经起作用,但现在不起作用了。该代码生成一个近似等级。我还没有为任何其他地方指定“列表”。当然,我一直在上下翻来覆去地用一种相当混乱的方式在笔记本上乱搞 df3是一个包含tweet的数据帧 我在Jupyter笔记本中使用python 3.6 有什么想法吗 dofe: 错误:类型错误:';列表';对象不能使用python3在级别级函数片段上调用,python,python-3.x,data-science,Python,Python 3.x,Data Science,我似乎无法纠正这个错误。它曾经起作用,但现在不起作用了。该代码生成一个近似等级。我还没有为任何其他地方指定“列表”。当然,我一直在上下翻来覆去地用一种相当混乱的方式在笔记本上乱搞 df3是一个包含tweet的数据帧 我在Jupyter笔记本中使用python 3.6 有什么想法吗 dofe: 错误: --------------------------------------------------------------------------- TypeError
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-50-f2e77b4afe86> in <module>()
33 - 15.59)
34
---> 35 df3['grade_level'] = df3.text.apply(get_grade_level)
~/anaconda3/lib/python3.6/site-packages/pandas/core/series.py in apply(self, func, convert_dtype, args, **kwds)
2549 else:
2550 values = self.asobject
-> 2551 mapped = lib.map_infer(values, f, convert=convert_dtype)
2552
2553 if len(mapped) and isinstance(mapped[0], Series):
pandas/_libs/src/inference.pyx in pandas._libs.lib.map_infer()
<ipython-input-50-f2e77b4afe86> in get_grade_level(text)
25 words = [word for word in words if word != '']
26 word_count += len(words)
---> 27 syllable_count += sum([get_syllable_count(word) for word in words])
28 if word_count is 0:
29 return 0
<ipython-input-50-f2e77b4afe86> in <listcomp>(.0)
25 words = [word for word in words if word != '']
26 word_count += len(words)
---> 27 syllable_count += sum([get_syllable_count(word) for word in words])
28 if word_count is 0:
29 return 0
<ipython-input-50-f2e77b4afe86> in get_syllable_count(word)
12 if (not len(word)) or (not word in cmu):
13 return 0
---> 14 return len([x for x in list(''.join(list(cmu[word])[-1])) if match(r'\d', x)])
15
16 def get_grade_level(text):
TypeError: 'list' object is not callable
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在()
33 - 15.59)
34
--->35 df3['grade\u level']=df3.text.apply(获取等级)
应用中的~/anaconda3/lib/python3.6/site-packages/pandas/core/series.py(self、func、convert\u dtype、args、**kwds)
2549其他:
2550值=self.asobject
->2551 mapped=lib.map\u推断(值,f,convert=convert\u数据类型)
2552
2553如果len(映射)和isinstance(映射[0],系列):
pandas/_libs/src/inference.pyx在pandas中。_libs.lib.map_infere()
在获取等级级别(文本)
25字=[逐字逐句,如果字!='']
26字计数+=len(字)
--->27音节计数+=总和([获取单词中单词的音节计数(单词)])
28如果字数为0:
29返回0
英寸(.0)
25字=[逐字逐句,如果字!='']
26字计数+=len(字)
--->27音节计数+=总和([获取单词中单词的音节计数(单词)])
28如果字数为0:
29返回0
在获取音节时计数(单词)
12如果(非文字)或(非cmu中的文字):
13返回0
--->14返回len([x代表列表中的x(''.join(列表(cmu[word])[-1]),如果匹配(r'\d',x)])
15
16 def get_grade_级别(文本):
TypeError:“列表”对象不可调用
检查len
、list
和match
是什么。你似乎重新分配了一些不应该分配的任务。我检查了这三个任务的类型。list=list len=build-in-function match=functional您确实为list
分配了一些内容,然后,list
是可调用的,因此此消息表示您重新分配了它。在return语句之前执行打印(键入(列表))
,并查看其内容。
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-50-f2e77b4afe86> in <module>()
33 - 15.59)
34
---> 35 df3['grade_level'] = df3.text.apply(get_grade_level)
~/anaconda3/lib/python3.6/site-packages/pandas/core/series.py in apply(self, func, convert_dtype, args, **kwds)
2549 else:
2550 values = self.asobject
-> 2551 mapped = lib.map_infer(values, f, convert=convert_dtype)
2552
2553 if len(mapped) and isinstance(mapped[0], Series):
pandas/_libs/src/inference.pyx in pandas._libs.lib.map_infer()
<ipython-input-50-f2e77b4afe86> in get_grade_level(text)
25 words = [word for word in words if word != '']
26 word_count += len(words)
---> 27 syllable_count += sum([get_syllable_count(word) for word in words])
28 if word_count is 0:
29 return 0
<ipython-input-50-f2e77b4afe86> in <listcomp>(.0)
25 words = [word for word in words if word != '']
26 word_count += len(words)
---> 27 syllable_count += sum([get_syllable_count(word) for word in words])
28 if word_count is 0:
29 return 0
<ipython-input-50-f2e77b4afe86> in get_syllable_count(word)
12 if (not len(word)) or (not word in cmu):
13 return 0
---> 14 return len([x for x in list(''.join(list(cmu[word])[-1])) if match(r'\d', x)])
15
16 def get_grade_level(text):
TypeError: 'list' object is not callable