由于我无法找到这个问题的一站式答案,所以我在从不同的线程中学习后发布了我的解决方案:
我使用pandas导入数据,如下所示
import pandas as pd
data=read_csv(".../file.csv",encoding='utf8')这导致了以下错误:
UnicodeDecodeError: 'utf8' codec can't decode byte 0x92 in position 352: invalid start type当我将编码更改为拉丁文-1时,可以避免这种情况。
data=read_csv(".../file.csv",encoding='Latin-1')这导致在尝试应用vectorizer.fit_transform()时出现错误。
ValueError: np.nan is an invalid document, expected byte or unicode string发布于 2017-05-08 19:10:21
使用“拉丁语-1”编码导入数据:
data=read_csv(".../file.csv",encoding='Latin-1')接下来,在使用以下方法执行vectorizer.fit_transform()时:
vectorizer.fit_transform(train['desc'].values.astype('U')) #This example is for a specific dictionary type which I had named train with desc as an key这应该能解决这个问题
https://stackoverflow.com/questions/43855500
复制相似问题