gpt4 book ai didi

python - 错误: 'list' object has no attribute 'lower'

转载 作者:行者123 更新时间:2023-12-03 08:24:09 26 4
gpt4 key购买 nike

因此,我创建了这段代码来计算两个不同的csv文件中两列之间的余弦相似度,这两列都包含作业描述行。

from sklearn.feature_extraction.text import CountVectorizer
from sklearn.metrics.pairwise import cosine_similarity
from sklearn.feature_extraction.text import TfidfVectorizer
import pandas as pd

df = df = pd.read_csv("Green jobs description.csv")
df2 = pd.read_csv("ExtractedData_2006.csv")
jobs = df.Description.tolist()
jobs2 = df2.Description.tolist()

train_set = [jobs, jobs2]

tfidf_vectorizer = TfidfVectorizer()
tfidf_matrix_train = tfidf_vectorizer.fit_transform(train_set) #finds the tfidf score with normalization
print "cosine scores ==> ",cosine_similarity(tfidf_matrix_train[0:1], tfidf_matrix_train)

因此,当我运行代码时,出现此错误,我将整个回溯包含在图片中以使其清晰可见

code traceback

有人可以帮我吗?

最佳答案

我想出了解决方法

train_set=jobs+jobs2
train_set=[tmp.lower() for tmp in train_set]

就是这样。我只需要在列表中的字符串下方添加。

关于python - 错误: 'list' object has no attribute 'lower' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47193139/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com