我面临这个属性错误,并且我陷入了如何处理浮点值(如果它们出现在推文中)的问题。流式推文必须小写并标记化,因此我使用了 split 函数。
有人可以帮我解决这个问题,有任何解决方法或解决方案吗?
这是error我正在…
AttributeError Traceback (most recent call last)
<ipython-input-28-fa278f6c3171> in <module>()
1 stop_words = []
----> 2 negfeats = [(word_feats(x for x in p_test.SentimentText[f].lower().split() if x not in stop_words), 'neg') for f in l]
3 posfeats = [(word_feats(x for x in p_test.SentimentText[f].lower().split() if x not in stop_words), 'pos') for f in p]
4
5 trainfeats = negfeats+ posfeats
AttributeError: 'float' object has no attribute 'lower'
这是我的代码
p_test = pd.read_csv('TrainSA.csv')
stop_words = [ ]
def word_feats(words):
return dict([(word, True) for word in words])
l = [ ]
for f in range(len(p_test)):
if p_test.Sentiment[f] == 0:
l.append(f)
p = [ ]
for f in range(len(p_test)):
if p_test.Sentiment[f] == 1:
p.append(f)
negfeats = [(word_feats(x for x in p_test.SentimentText[f].lower().split() if x not in stop_words), 'neg') for f in l]
posfeats = [(word_feats(x for x in p_test.SentimentText[f].lower().split() if x not in stop_words), 'pos') for f in p]
trainfeats = negfeats+ posfeats
print len(trainfeats)
import random
random.shuffle(trainfeats)
print(len(trainfeats))
p_train = pd.read_csv('TrainSA.csv')
l_t = []
for f in range(len(p_train)):
if p_train.Sentiment[f] == 0:
l_t.append(f)
p_t = []
for f in range(len(p_train)):
if p_train.Sentiment[f] == 1:
p_t.append(f)
print len(l_t)
print len(p_t)
我尝试了很多方法,但仍然无法让他们使用 lower 和 split 功能。
谢谢@迪克·克尼普。是的,它是 Pandas CSV 阅读器。你的建议奏效了。
以下是通过指定字段数据类型为我工作的Python代码,
(在本例中为它的字符串)
p_test = pd.read_csv('TrainSA.csv')
p_test.SentimentText=p_test.SentimentText.astype(str)
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)