【发布时间】:2020-02-19 12:00:49
【问题描述】:
def create_tfidf_dictionary(x, transformed_file, features):
vector_coo = transformed_file[x.name].tocoo()
vector_coo.col = features.iloc[vector_coo.col].values
dict_from_coo = dict(zip(vector_coo.col, vector_coo.data))
return dict_from_coo
def replace_tfidf_words(x, transformed_file, features):
dictionary = create_tfidf_dictionary(x, transformed_file, features)
return list(map(lambda y:dictionary[f'{y}'], x.title.split()))
%%time
replaced_tfidf_scores = file_weighting.apply(lambda x: replace_tfidf_words(x, transformed, features), axis=1)
运行此代码时出现以下错误。
TypeError Traceback(最近调用 最后)在
~\Anaconda3\lib\site-packages\pandas\core\frame.py in apply(self, func、轴、广播、原始、减少、result_type、args、**kwds)6911 kwds=kwds, 6912) -> 6913 return op.get_result() 6914 6915 def applymap(self, func):
~\Anaconda3\lib\site-packages\pandas\core\apply.py 在 get_result(self) 第184章 185 --> 186 返回 self.apply_standard() 187 188 def apply_empty_result(自我):
~\Anaconda3\lib\site-packages\pandas\core\apply.py 在 应用标准(自我) 290 291 # 使用序列生成器计算结果 --> 292 self.apply_series_generator() 293 294 # 包装结果
~\Anaconda3\lib\site-packages\pandas\core\apply.py 在 apply_series_generator(self) 319尝试: 320 for i, v in enumerate(series_gen): --> 321 个结果[i] = self.f(v) 322 键.append(v.name) 323 例外为 e:
在 (x) 中
在 replace_tfidf_words(x, 转换文件,特征) 24''' 25 字典 = create_tfidf_dictionary(x,transformed_file,特征) ---> 26 返回列表(map(lambda y:dictionary[f'{y}'], x.title.split()))
TypeError: ("'list' object is not callable", '发生在索引 0')
我是python新手,请帮我解决这个错误。
【问题讨论】:
-
请改进您问题的格式。很难看到发生了什么。特别是我不知道
%%time行在做什么。 -
在此之前检查您的代码方式 - 我相信您可能在某处有
list =,从而覆盖内置名称('list' object is not callable建议名称list不是可调用的 - 当它通常应该)。
标签: python pandas numpy machine-learning