cjhutto / vaderSentiment

VADER Sentiment Analysis. VADER (Valence Aware Dictionary and sEntiment Reasoner) is a lexicon and rule-based sentiment analysis tool that is specifically attuned to sentiments expressed in social media, and works well on texts from other domains.
MIT License
4.38k stars 1k forks source link

How to successfully loop the sentiment scores into an existing csv? #103

Closed pelas95 closed 4 years ago

pelas95 commented 4 years ago

Hi,

Do you have any tips for applying the sentiment scores to an existing CSV? My data comprises of two columns, channelID and user comment. In the output, I can only get the first three rows with sentiment scores. My row of channel ID is also cleared.

I've tried reformatting my CSV using text-to-columns from fixed-with to delimited by tab but it did not help. Delimiting by commas is not possible, since the comment text contains columns.

I'm only a beginner and have been stuck with this issue for a while. Photos of my code and faulty output below:

Screen Shot 2020-07-07 at 3 25 44 PM Screen Shot 2020-07-07 at 3 29 54 PM

Many thanks!

/P

pelas95 commented 4 years ago

Typo in the output generation. should be:

vs_results = [vs(row) for row in df['comment']] vs_df = pd.DataFrame(vs_results) text_df = pd.DataFrame(df, columns = ['channelId','comment']) final_df = text_df.join(vs_df)

final_df.to_csv('name.csv')