TypeError:(“'list'对象不可调用”,'发生在索引0')

问题描述 投票:0回答:1
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,axis,broadcast,raw,reduce,result_type,args,** kwds)6911kwds = kwds,6912​​)-> 6913 return op.get_result()6914 6915 def applymap(self,func):

〜\ Anaconda3 \ lib \ site-packages \ pandas \ core \ apply.py in get_result(self)184返回self.apply_raw()185-> 186返回self.apply_standard()187188 def apply_empty_result(self):

〜\ Anaconda3 \ lib \ site-packages \ pandas \ core \ apply.py在apply_standard(个体)290291#使用系列生成器计算结果-> 292 self.apply_series_generator()293294#换行结果

〜\ Anaconda3 \ lib \ site-packages \ pandas \ core \ apply.py在apply_series_generator(个体)319尝试:i,v中的320枚举(series_gen):-> 321个结果[i] = self.f(v)322个key.append(v.name)323例外,例如e:

in(x)

在replace_tfidf_words(x,transformd_file,功能)24'''25字典= create_tfidf_dictionary(x,transformd_file,features)---> 26个返回列表(map(lambda y:dictionary [f'{y}'],x.title.split()))

TypeError :(“'list'对象不可调用”,“发生在索引0”)

我是python的新手,请帮助我解决此错误。

python pandas numpy machine-learning
1个回答
0
投票

这是一个常见错误,通常会在为名为list的变量设置一些值时发生。考虑下面的代码:

© www.soinside.com 2019 - 2024. All rights reserved.