我在推特上做情绪分析。在计算推特的情绪之前,我已经做了一个算法来删除表情符号和一些特殊的字符。在此之后,没有表情符号和特殊人物的推文被放入了一个带有情感的数据框架中。以下是代码:
x = 0
a = 0
d = {}
for vertaling in df['text']:
bericht = re.sub('[^A-Za-z0-9]', ' ', df['text'].iloc[x])
bericht = re.sub(' +',' ', bericht)
translations = translator.translate([bericht], dest='en')
for translation in translations:
a = a + 1
print(a)
print(translation.origin)
analysis = TextBlob(translation.text)
print(analysis.sentiment)
x = x + 1
d[translation.origin] = analysis.sentiment
c = ['Tweets','Sentiment']
df2 = pd.DataFrame(list(d.items()), columns=c)我想要原始的推特和深思熟虑的情绪相结合。上面提供的代码将过滤后的tweet与这一行的情感结合在一起:
c = ['Tweets','Sentiment']
df2 = pd.DataFrame(list(d.items()), columns=c)
有没有人知道我能把原始的推文和数据挖掘中的新的计算情绪结合起来呢?
发布于 2018-05-17 11:16:52
不过,我自己找到了解决办法。解决方案:
x = 0
a = 0
d = {}
#df2 = pd.DataFrame(['Tweets', 'Sentiment'])
df['Tweets'] = ""
df['Sentiment'] = ""
for vertaling in df['text']:
df['Tweets'].iloc[x] = df['text'].iloc[x]
bericht = re.sub('[^A-Za-z0-9]', ' ', df['text'].iloc[x])
bericht = re.sub(' +',' ', bericht)
translations = translator.translate([bericht], dest='en')
for translation in translations:
a = a + 1
print(a)
print(translation.origin)
analysis = TextBlob(translation.text)
df['Sentiment'].iloc[x] = analysis.sentiment
x = x + 1
d[translation.origin] = analysis.sentiment这结合了新列和我现有的列。
https://stackoverflow.com/questions/50387110
复制相似问题