jieba分词时出现AttributeError: 'float' object has no attribute 'decode'
作为一个小白,因为参加比赛的缘故自学情感分析,把所遇到的困难写下来,也算以后少走弯路 当使用以下代码进行读取Excel文件,并进行jieba分词时,最后结果反馈AttributeError: 'float' object has no attribute 'decode'
import numpy as np
import pandas as pd
from gensim.models.word2vec import Word2Vec
#读取原始信息
neg=pd.read_excel('Disney-jd-comment.xlsx',encoding='utf-8')
print(neg)
print(neg.columns)
print('---------------------')
neg['words']=neg['comment'].apply(lambda x: jieba.lcut(x))
print(neg)
既然说float不行,那么在读取的时候把类型改为str。如下
neg=pd.read_excel('Disney-jd-comment.xlsx',encoding='utf-8').astype(str)
这样就可以了进行分词了