【发布时间】:2021-02-18 22:45:40
【问题描述】:
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.metrics.pairwise import cosine_similarity
tfidf = TfidfVectorizer(analyzer='word', stop_words='english')
age_matrix = tfidf.fit_transform(df['age'])
运行上述代码时可能会出现以下错误。
为什么会这样?
请帮帮我。 提前致谢。
/usr/local/lib/python3.6/dist-packages/pandas/core/indexes/base.py get_loc(self, key, method, tolerance) 2895 返回 self._engine.get_loc(casted_key) 2896 除了 KeyError 作为错误: -> 2897 如果容差不是无,则从 err 2898 2899 引发 KeyError(key):
KeyError: '年龄'
我的数据集如下。
Gender product 0
age
18 F Bags-Mens 5
18 F Bags-Women 4
18 F Books-Academic 4
18 F Books-Children 5
18 F Books-Comics 7
.. ... ... ..
44 M Books-Comics 2
44 M Clothing-Mens 1
44 M Clothing-Women 1
44 M Footwear-Women 1
44 M Home and kitchen-Furnishing 2
[1202 rows x 3 columns]
【问题讨论】:
标签: python scikit-learn feature-extraction