May-14-2017, 07:02 PM
Hello python experts,
for an university project I want to do an sentiment analysis of twitter tweets with the NLTK package. Therefore, my code looks this:
[Image: sUzLk]
Unfortunatly, I get four rows for every tweet instead of only one. What do I have to do to fix this and is it possible to get the results of the sentiment analysis in different columns? The structure of the file should look like this:
Tweet,Compound,Negativ,Neutral,PossitiveÂ
Thanks in advance!
for an university project I want to do an sentiment analysis of twitter tweets with the NLTK package. Therefore, my code looks this:
sid = SentimentIntensityAnalyzer() for sentence in tweets.Mess: Â Â Â Â print(sentence) Â Â Â Â ss = sid.polarity_scores(sentence) Â Â Â Â for k in sorted(ss): Â Â Â Â Â Â print('{0}: {1}, '.format(k, ss[k]), end='') Â Â Â Â Â Â print() Â Â Â Â Â Â with open('OutputSentiment.csv','a') as outfile: Â Â Â Â Â Â Â Â outfile.write(str(sentence) + ',' + str(k) + ',' + str(ss[k]) + '\n')The results in the output file look this:
[Image: sUzLk]
Unfortunatly, I get four rows for every tweet instead of only one. What do I have to do to fix this and is it possible to get the results of the sentiment analysis in different columns? The structure of the file should look like this:
Tweet,Compound,Negativ,Neutral,PossitiveÂ
Thanks in advance!