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!