Sentiment Analysis: YouTube comments on NASA Mars landing

import pandas as pd
df=pd.read_csv('landing.csv')
print(df)
Output:Unnamed: 0      time                            comment
0 0 0:03 was uppp everyone
1 1 0:05 this is it
2 2 0:07 bobchamp
3 3 0:07 Omg Im so excited for this
4 4 0:07 french here
... ... ... ...
16125 16125 2:11:41 R I P David Bowie
16126 16126 2:11:41 _perfect_effect_ nice to meet you
16127 16127 2:11:41 its finished
16128 16128 2:11:42 Bye chat
16129 16129 2:11:43 Congratulations team Go NASA

[16130 rows x 3 columns]
import nltk
nltk.download("vader_lexicon")
from nltk.sentiment.vader import SentimentIntensityAnalyzer
vader = SentimentIntensityAnalyzer()
df["scores"] = df["comment"].apply(lambda comment: vader.polarity_scores(comment))
df.head()
df["compound"]=df["scores"].apply(lambda score_dict:score_dict["compound"])df["sentiment"]=df["compound"].apply(lambda c:"pos" if c>=0 else "neg")
print(df)
Unnamed: 0      time                            comment  \
0 0 0:03 was uppp everyone
1 1 0:05 this is it
2 2 0:07 bobchamp
3 3 0:07 Omg Im so excited for this
4 4 0:07 french here
... ... ... ...
16125 16125 2:11:41 R I P David Bowie
16126 16126 2:11:41 _perfect_effect_ nice to meet you
16127 16127 2:11:41 its finished
16128 16128 2:11:42 Bye chat
16129 16129 2:11:43 Congratulations team Go NASA

scores compound sentiment
0 {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound... 0.0000 pos
1 {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound... 0.0000 pos
2 {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound... 0.0000 pos
3 {'neg': 0.0, 'neu': 0.616, 'pos': 0.384, 'comp... 0.4795 pos
4 {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound... 0.0000 pos
... ... ... ...
16125 {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound... 0.0000 pos
16126 {'neg': 0.0, 'neu': 0.588, 'pos': 0.412, 'comp... 0.4215 pos
16127 {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound... 0.0000 pos
16128 {'neg': 0.0, 'neu': 1.0, 'pos': 0.0, 'compound... 0.0000 pos
16129 {'neg': 0.0, 'neu': 0.435, 'pos': 0.565, 'comp... 0.5994 pos

--

--

--

Geopolitics and Data Science enthusiast.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

A Product Manager’s Guide to Machine Learning: Core Ideas

RANDOM FOREST

Addition and Subtraction using Recurrent Neural Networks.

Data Science: Machine Learning Models Metrics

Predicting Sign Language Based On Hand Signals

Detecting Suicide Risk in Chat Applications

Ensemble: Power Learning

It’s all Variational …

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Anmol Hans

Anmol Hans

Geopolitics and Data Science enthusiast.

More from Medium

Sentiment analysis of tweets after the announcement of street fighters 6

IMDB Rating Prediction using Linear Regression and Web Scraping

Travel Destination ✈️ Recommendation for Airbnb Users with XGBoost

Sentiment Analysis