我面對這個屬性錯誤,我被困在如何處理浮動值,如果他們出現在tweet.The流tweet必須降低和標記化所以我使用了分割功能。AttributeError:'float'對象沒有屬性'lower'
有人可以幫我解決它,任何解決方法或解決方案..?
這裏的錯誤其中M剛開....
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)
我嘗試了很多方法,但仍然無法讓它們使用較低和分割功能。
顯然'p_test.SentimentText [f]'是一個浮點數,而不是一個字符串。你不能在float上調用'lower()'。 – Kevin
它通常有助於包含帶有追溯的實際錯誤文本,而不是僅提及它 - 否則人們必須猜測錯誤可能來自哪裏。 – Lav