Sentiment Analysis of Anthem’s Game Launch in Python
By: William Masse
Tags: Towards Data Science, Sentiment Analysis, Python, Videogames, Data Science

Video game launches are plagued by drama. From misleading pre-order bundles, to games that are far from complete at launch, big publishers have quite a bit of risk to manage when it comes to deciding how and when a game launches. I thought it might be a fun project to see just how the sentiment surrounding a game changes during its launch, and the AAA title Anthem was the perfect game for this little project. (As an FYI, I’m writing this article before the official February 22nd launch of the game)

Before we get started Anthem has a unique launch timeline that could impact individual’s sentiment around the game.

Anthem had a ‘Demo Weekend’ from Friday, February 1st to Sunday, February 3rd

Anthem launched ‘Early’ for members of EA Access on Friday, February 15th

Anthem launches officially for everyone on February 22nd

So let’s get started!

I’ll try my best to describe all the packages I used as I go along, but for reference here are my import statements!

%matplotlib inline

from twitterscraper import query_tweets

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

import datetime as dt

import pandas as pd

from langdetect import detect

import matplotlib.pyplot as plt

import seaborn as sns analyzer = SentimentIntensityAnalyzer()

Scraping Twitter Data

There are a million ways to get data from twitter, but I chose to use the package twitterscraper by taspinar, a wrapper for beautifulSoup that makes getting tweets easy. I like this package because not only do you avoid having to request an API key from twitter, but also because the webscraper doesn’t have any of the limitations of twitter’s API.

With from twitterscraper import query_tweets , getting all the tweets I needed was simple.

begin_date = dt.datetime.strptime("Jan 15 2019", "%b %d %Y").date()

tweets = query_tweets("#Anthem OR #AnthemGame",begindate=begin_date)

This will take some time…so go tackle a stronghold while you wait! When you’re done you should have a nice long list of twitterscraper objects.

print(len(tweets))

102418

102,418 tweets about Anthem!

Twitterscraper objects have an easy to use __dict__ method that returns all the data we could ever want for a tweet in dictionary form.

tweets[1].__dict__ {'user': '_WECKLESS',

'fullname': 'WECKLESS™',

'id': '1085323189738192897',

'url': '/_WECKLESS/status/1085323189738192897',

'timestamp': datetime.datetime(2019, 1, 15, 23, 49, 47),

'text': 'Here is my GIF #AnthemGame pic.twitter.com/jCNjiWQnmJ',

'replies': 0,

'retweets': 0,

'likes': 2,

'html': '<p class="TweetTextSize js-tweet-text tweet-text" data-aria-label-part="0" lang="en">Here is my GIF <span class="twitter-hashflag-container"><a class="twitter-hashtag pretty-link js-nav" data-query-source="hashtag_click" dir="ltr" href="/hashtag/AnthemGame?src=hash">
#
<b><strong>AnthemGame</strong></b></a><a dir="ltr" href="/hashtag/AnthemGame?src=hash"><img alt="" class="twitter-hashflag" draggable="false" src="https://abs.twimg.com/hashflags/AnthemGame_Anthem/AnthemGame_Anthem.png"/></a></span> <a class="twitter-timeline-link u-hidden" data-pre-embedded="true" dir="ltr" href="https://t.co/jCNjiWQnmJ">pic.twitter.com/jCNjiWQnmJ</a></p>'}

We can see this dictionary has username, unique tweet id’s, number of replies, retweets, and likes the tweet has, and most importantly the tweet’s text! We’ll put all these tweets into a pandas dataframe so they are easy to work with! (I also saved my tweets into a file at this point so if I ever wanted to re-run my analysis I wouldn’t have to go through the webscraping process again.)

tweet_list = (t.__dict__ for t in tweets)

df = pd.DataFrame(tweet_list)

And here is what our new dataframe looks like!

Notice how some tweets are not in english. We’ll deal with that in the next step!

Language and Sentiment Analysis

We’re going to tackle two things in this next step. First off notice how not all of our tweets are in English? Although we could translate our tweets and attempt to get some sentiment from them, I thought it would just be easier and cleaner to remove tweets that were not in English. To do that we’ll need to tag every tweet with its language. Not to worry, theres a library for that! Langdetect by Mimino66's detect function is all we need to identify the language of our tweets. We can load in the necessary function with from langdetect import detect

We’ll make a new column in our dataframe by mapping the detect() function over our text data and then keep only the tweets that are in English.

df['lang'] = df['text'].map(lambda x: detect(x))

df = df[df['lang']=='en']

When this step was complete I was left with just 77,740 tweets.

Now with that out of the way we can begin to run some text analysis on our tweets. VADER Sentiment Analysis is a popular python package for getting the sentiment of a piece of text, its particularly good for social media data and is ready to go out of the box!

We need to import its SentimentIntensityAnalyzer and initialize it.

from vaderSentiment.vaderSentiment import SentimentIntensityAnalyzer

analyzer = SentimentIntensityAnalyzer()

VADER will return a dictionary of 4 scores for any text you pass it; Positive, Neutral, Negative, and Compound scores, all ranging from -1 to 1. We’ll be mostly interested in the compound scores for tracking the overall sentiment of a tweet.

From here we make a new Series of data that contains the sentiment of our tweet’s text and concatenate it to our original dataframe.

sentiment = df['text'].apply(lambda x: analyzer.polarity_scores(x))

df = pd.concat([df,sentiment.apply(pd.Series)],1)

Here is what our final dataframe looks like. We can see our tweets are in english, and each has a set of sentiment scores associated with it.