在列表列表上获取错误:TypeError:“int”对象不是iterab

2024-04-25 06:40:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试调用函数tfidf对一个列表total\u all。我在运行下面的行时收到一条错误消息:TypeError:'int'object is not iterable

tfidf(total_all)

def tfidf(documents):
   global dftfidf
   dftfidf = pd.DataFrame() 
   tokenized_documents = [tokenize(d) for d in documents]
   idf = inverse_document_frequencies(tokenized_documents)
   for term in idf.keys():
       tf = sublinear_term_frequency(term, document)
       doc_tfidf.append(tf * idf[term])
       tfidf_documents.append(doc_tfidf)
       dftfidf=pd.DataFrame(data ={'term frequency':tf,'tfidf':doc_tfidf}) 
   return dftfidf

tfidf(total_all)

Tags: indataframefordoctfalldocumentdocuments