cmc/cleberg.net

My personal web garden & blog.

clone: git clone https://gitbay.org/cmc/cleberg.net.git

main: content/blog/2020-07-20-video-game-sales.org · raw

  1#+date:        [2020-07-20 Mon 00:00:00]
  2#+title:       Data Analysis: Video Games Sales Data
  3#+description: A simple data analysis of the video games sales dataset.
  4#+slug:        video-game-sales
  5#+filetags:    :personal:
  6
  7* Background Information
  8
  9This dataset (obtained from [[https://www.kaggle.com/gregorut/videogamesales/data][Kaggle]]) contains a list of video games with sales
 10greater than 100,000 copies. It was generated by a scrape of vgchartz.com.
 11
 12Fields include:
 13
 14- Rank: Ranking of overall sales
 15- Name: The game name
 16- Platform: Platform of the game release (i.e. PC,PS4, etc.)
 17- Year: Year of the game's release
 18- Genre: Genre of the game
 19- Publisher: Publisher of the game
 20- NA_{Sales}: Sales in North America (in millions)
 21- EU_{Sales}: Sales in Europe (in millions)
 22- JP_{Sales}: Sales in Japan (in millions)
 23- Other_{Sales}: Sales in the rest of the world (in millions)
 24- Global_{Sales}: Total worldwide sales.
 25
 26There are 16,598 records. 2 records were dropped due to incomplete information.
 27
 28* Import the Data
 29
 30#+begin_src python
 31# Import the Python libraries we will be using
 32import pandas as pd
 33import numpy as np
 34import seaborn as sns; sns.set()
 35import matplotlib.pyplot as plt
 36
 37# Load the file using the path to the downloaded file
 38file = r'video_game_sales.csv'
 39df = pd.read_csv(file)
 40df
 41#+end_src
 42
 43* Explore the Data
 44
 45#+begin_src python
 46# With the description function, we can see the basic stats. For example, we can
 47# also see that the 'Year' column has some incomplete values.
 48df.describe()
 49#+end_src
 50
 51#+begin_src python
 52# This function shows the rows and columns of NaN values. For example, df[179,3] = nan
 53np.where(pd.isnull(df))
 54
 55(array([179, ..., 16553], dtype=int64),
 56 array([3, ..., 5], dtype=int64))
 57#+end_src
 58
 59* Visualize the Data
 60
 61#+begin_src python
 62# This function plots the global sales by platform
 63sns.catplot(x='Platform', y='Global_Sales', data=df, jitter=False).set_xticklabels(rotation=90)
 64#+end_src
 65
 66#+begin_src python
 67# This function plots the global sales by genre
 68sns.catplot(x='Genre', y='Global_Sales', data=df, jitter=False).set_xticklabels(rotation=45)
 69#+end_src
 70
 71#+begin_src python
 72# This function plots the global sales by year
 73sns.lmplot(x='Year', y='Global_Sales', data=df).set_xticklabels(rotation=45)
 74#+end_src
 75
 76#+begin_src python
 77# This function plots four different lines to show sales from different regions.
 78# The global sales plot line is commented-out, but can be included for comparison
 79df2 = df.groupby('Year').sum()
 80years = range(1980,2019)
 81
 82a = df2['NA_Sales']
 83b = df2['EU_Sales']
 84c = df2['JP_Sales']
 85d = df2['Other_Sales']
 86# e = df2['Global_Sales']
 87
 88fig, ax = plt.subplots(figsize=(12,12))
 89ax.set_ylabel('Region Sales (in Millions)')
 90ax.set_xlabel('Year')
 91
 92ax.plot(years, a, label='NA_Sales')
 93ax.plot(years, b, label='EU_Sales')
 94ax.plot(years, c, label='JP_Sales')
 95ax.plot(years, d, label='Other_Sales')
 96# ax.plot(years, e, label='Global_Sales')
 97
 98ax.legend()
 99plt.show()
100#+end_src
101
102** Investigate Outliers
103
104#+begin_src python
105# Find the game with the highest sales in North America
106df.loc[df['NA_Sales'].idxmax()]
107
108Rank                     1
109Name            Wii Sports
110Platform               Wii
111Year                  2006
112Genre               Sports
113Publisher         Nintendo
114NA_Sales             41.49
115EU_Sales             29.02
116JP_Sales              3.77
117Other_Sales           8.46
118Global_Sales         82.74
119Name: 0, dtype: object
120
121# Explore statistics in the year 2006 (highest selling year)
122df3 = df[(df['Year'] == 2006)]
123df3.describe()
124#+end_src
125
126#+begin_src python
127# Plot the results of the previous dataframe (games from 2006) - we can see the year's results were largely carried by Wii Sports
128sns.catplot(x="Genre", y="Global_Sales", data=df3, jitter=False).set_xticklabels(rotation=45)
129#+end_src
130
131#+begin_src python
132# We can see 4 outliers in the graph above, so let's get the top 5 games from that dataframe
133# The results below show that Nintendo had all top 5 games (3 on the Wii and 2 on the DS)
134df3.sort_values(by=['Global_Sales'], ascending=False).head(5)
135#+end_src
136
137* Discussion
138
139The purpose of exploring datasets is to ask questions, answer questions, and
140discover intelligence that can be used to inform decision-making. So, what have
141we found in this dataset?
142
143Today we simply explored a publicly-available dataset to see what kind of
144information it contained. During that exploration, we found that video game
145sales peaked in 2006. That peak was largely due to Nintendo, who sold the top 5
146games in 2006 and has a number of games in the top-10 list for the years
1471980-2020. Additionally, the top four platforms by global sales (Wii, NES, GB,
148DS) are owned by Nintendo.
149
150We didn't explore everything this dataset has to offer, but we can tell from a
151brief analysis that Nintendo seems to rule sales in the video gaming world.
152Further analysis could provide insight into which genres, regions, publishers,
153or world events are correlated with sales.