簡體   English   中英

AttributeError: 'list' object 在詞頻逆文檔頻率中沒有屬性 'lower'

[英]AttributeError: 'list' object has no attribute 'lower' in term frequency inverse document frequency

我在堆棧溢出中發現了很多與此問題相關的帖子。 我嘗試了這些,但仍然遇到同樣的錯誤。 我正在使用 python 3.7 並為我的 urdu 數據集編寫了以下代碼

Tfidf_vect = TfidfVectorizer()

x=Tfidf_vect.fit(df['final'])

但收到錯誤消息AttributeError: 'list' object has no attribute 'lower'然后我發現這個堆棧溢出帖子

AttributeError: 'list' object has no attribute 'lower' : clustering
. 這表明 TfidfVectorizer 只需要一個句子列表所以我按照解決方案中提到的步驟 & 修改代碼 & 使用以下代碼

vectors = TfidfVectorizer() dataset_list=df['final'].values.ravel().tolist() X = vectors.fit_transform(dataset_list)

示例數據集在此處可用 仍然是相同的錯誤消息。您能建議我糾正的步驟嗎?

fit_transform 方法接受一個迭代,它產生 str、unicode 或文件對象作為參數。 您的輸入數據中可能存在被忽略的項目。 確保所有項目都是 str。 通過以下代碼段檢查。

False in map((lambda x: type(x) == str), df['final'])

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM