AttributeError: 'float' 对象没有属性 'lower' [英] AttributeError: 'float' object has no attribute 'lower'
问题描述
我正面临这个属性错误,我一直在纠结如何处理出现在推文中的浮点值.流推文必须小写并标记化,所以我使用了拆分功能.
I'm facing this attribute error and I'm stuck at how to handle float values if they appear in a tweet.The streaming tweet has to be lower cased and tokenized so i have used split function.
有人可以帮我处理它吗,任何解决方法或解决方案..?
Can somebody please help me to deal with it, any workaround or solution ..?
这是我刚开始的错误....
Here's the error which m gettin....
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功能.
I tried many ways but still not able to get them to use lower and split function.
推荐答案
谢谢@Dick Kniep.是的,它是 Pandas CSV 阅读器.你的建议奏效了.以下是通过指定字段数据类型对我有用的python代码,(在这种情况下,它的字符串)
Thank you @Dick Kniep. Yes,it is Pandas CSV reader. Your suggestion worked. Following is the python code which worked for me by specifying the field datatype, (in this case, its string)
p_test = pd.read_csv('TrainSA.csv')
p_test.SentimentText=p_test.SentimentText.astype(str)
这篇关于AttributeError: 'float' 对象没有属性 'lower'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!