Data Exploration: Video Game Sales

Background Information

This dataset (obtained from Kaggle) contains a list of video games with sales greater than 100,000 copies. It was generated by a scrape of vgchartz.com.

Fields include:

  • Rank - Ranking of overall sales
  • Name - The games name
  • Platform - Platform of the games release (i.e. PC,PS4, etc.)
  • Year - Year of the game's release
  • Genre - Genre of the game
  • Publisher - Publisher of the game
  • NA_Sales - Sales in North America (in millions)
  • EU_Sales - Sales in Europe (in millions)
  • JP_Sales - Sales in Japan (in millions)
  • Other_Sales - Sales in the rest of the world (in millions)
  • Global_Sales - Total worldwide sales.

There are 16,598 records. 2 records were dropped due to incomplete information.

Import the Data

# Import the Python libraries we will be using
import pandas as pd
import numpy as np
import seaborn as sns; sns.set()
import matplotlib.pyplot as plt
# Download the file from this URL (https://gitlab.com/christian-cleberg/data-science/-/raw/master/data_files/video_game_sales.csv)
# Load the file using the path to the downloaded file
file = r'video_game_sales.csv'
df = pd.read_csv(file)
df

DataFrame result

Explore the Data

# With the description function, we can see the basic stats. For example, we can also see that the 'Year' column has some incomplete values.
df.describe()

df.describe() result

# This function shows the rows and columns of NaN values. For example, df[179,3] = nan
np.where(pd.isnull(df))

(array([  179,   377,   431,   470,   470,   607,   624,   649,   652,
          711,   782,  1126,  1133,  1303,  1303,  1433,  1498,  1513,
         1585,  1649,  1662,  1697,  1837,  1990,  2019,  2086,  2113,
         2114,  2134,  2145,  2173,  2222,  2286,  2295,  2415,  2422,
         2484,  2497,  2528,  2586,  2776,  2786,  2838,  2947,  3049,
         3141,  3159,  3166,  3194,  3217,  3238,  3346,  3421,  3468,
         3501,  3715,  3753,  3766,  3880,  3952,  4145,  4145,  4151,
         4199,  4232,  4330,  4378,  4380,  4469,  4472,  4526,  4536,
         4635,  4683,  4791,  4797,  4858,  4865,  4934,  5061,  5078,
         5162,  5171,  5195,  5196,  5240,  5302,  5302,  5508,  5618,
         5625,  5647,  5657,  5669,  5769,  5798,  5838,  5861,  5870,
         5901,  5913,  6042,  6125,  6153,  6195,  6211,  6272,  6272,
         6283,  6314,  6316,  6319,  6401,  6437,  6496,  6562,  6647,
         6648,  6777,  6806,  6832,  6849,  6919,  6926,  6937,  6966,
         6968,  7035,  7181,  7208,  7213,  7351,  7351,  7369,  7370,
         7382,  7406,  7423,  7470,  7615,  7648,  7720,  7908,  7946,
         7953,  8044,  8086,  8157,  8167,  8204,  8223,  8313,  8330,
         8334,  8341,  8368,  8376,  8439,  8503,  8553,  8620,  8707,
         8760,  8770,  8848,  8896,  8899,  8929,  9081,  9151,  9171,
         9251,  9310,  9392,  9475,  9517,  9522,  9667,  9692,  9742,
         9749,  9749,  9769,  9815,  9820,  9821,  9840,  9868,  9981,
        10045, 10272, 10362, 10382, 10465, 10494, 10494, 10559, 10690,
        10758, 10792, 10829, 10979, 10997, 11076, 11076, 11108, 11142,
        11323, 11331, 11376, 11409, 11455, 11526, 11543, 11573, 11755,
        11798, 11921, 11938, 11976, 12015, 12028, 12127, 12129, 12135,
        12184, 12212, 12238, 12248, 12487, 12487, 12517, 12517, 12531,
        12626, 12666, 12709, 12749, 12807, 12825, 12879, 12915, 12922,
        12929, 13055, 13156, 13278, 13278, 13477, 13665, 13672, 13672,
        13675, 13733, 13870, 13962, 13962, 14046, 14055, 14056, 14087,
        14087, 14098, 14160, 14273, 14296, 14296, 14311, 14312, 14377,
        14473, 14522, 14583, 14676, 14696, 14698, 14849, 14855, 14876,
        14925, 14942, 14942, 14997, 14998, 14999, 15056, 15197, 15208,
        15261, 15261, 15316, 15325, 15353, 15476, 15579, 15606, 15652,
        15697, 15717, 15739, 15788, 15811, 15865, 15876, 15878, 15900,
        15915, 15915, 16057, 16058, 16065, 16191, 16191, 16194, 16198,
        16198, 16208, 16229, 16229, 16246, 16307, 16327, 16366, 16367,
        16427, 16493, 16494, 16543, 16553], dtype=int64),
 array([3, 3, 3, 3, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 3, 3, 3, 3, 5, 3,
        3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,
        3, 3, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 3, 3, 5, 3, 3, 3, 3,
        3, 3, 3, 3, 5, 3, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5,
        3, 3, 3, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 3,
        3, 3, 3, 5, 3, 5, 3, 5, 3, 3, 3, 5, 3, 3, 3, 3, 3, 3, 3, 5, 3, 3,
        5, 3, 3, 3, 3, 3, 5, 3, 3, 3, 3, 3, 5, 3, 3, 3, 3, 3, 3, 3, 5, 3,
        5, 5, 3, 3, 5, 3, 3, 3, 3, 5, 5, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5,
        3, 3, 3, 3, 3, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 3, 5, 3, 3,
        3, 3, 3, 3, 3, 3, 5, 3, 3, 3, 3, 3, 3, 3, 5, 3, 3, 3, 3, 3, 3, 3,
        3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 5, 3, 5, 3, 3, 3, 3, 3, 3, 3, 3, 3,
        3, 3, 3, 3, 3, 5, 3, 3, 3, 5, 3, 3, 3, 3, 5, 3, 3, 3, 3, 5, 3, 3,
        3, 3, 5, 5, 3, 3, 3, 3, 3, 3, 3, 5, 3, 3, 3, 3, 3, 5, 3, 3, 3, 5,
        3, 3, 3, 5, 3, 5, 5, 3, 3, 3, 3, 3, 3, 3, 5, 3, 3, 3, 3, 3, 3, 5,
        3, 3, 3, 3, 5, 3, 3, 5, 5, 3, 5, 3, 3, 3, 3, 5, 3, 3, 5, 5, 5],
       dtype=int64))

Visualize the Data

# This function plots the global sales by platform
sns.catplot(x='Platform', y='Global_Sales', data=df, jitter=False).set_xticklabels(rotation=90)

plot of global sales by platform

# This function plots the global sales by genre
sns.catplot(x='Genre', y='Global_Sales', data=df, jitter=False).set_xticklabels(rotation=45)

plot of global sales by genre

# This function plots the global sales by year
sns.lmplot(x='Year', y='Global_Sales', data=df).set_xticklabels(rotation=45)

plot of global sales by year

# This function plots four different lines to show sales from different regions.
# The global sales plot line is commented-out, but can be included for comparison
df2 = df.groupby('Year').sum()
years = range(1980,2019)

a = df2['NA_Sales']
b = df2['EU_Sales']
c = df2['JP_Sales']
d = df2['Other_Sales']
# e = df2['Global_Sales']

fig, ax = plt.subplots(figsize=(12,12))
ax.set_ylabel('Region Sales (in Millions)')
ax.set_xlabel('Year')

ax.plot(years, a, label='NA_Sales')
ax.plot(years, b, label='EU_Sales')
ax.plot(years, c, label='JP_Sales')
ax.plot(years, d, label='Other_Sales')
# ax.plot(years, e, label='Global_Sales')

ax.legend()
plt.show()

plot of regional sales by year

Investigate Outliers

# Find the game with the highest sales in North America
df.loc[df['NA_Sales'].idxmax()]
Rank                     1
Name            Wii Sports
Platform               Wii
Year                  2006
Genre               Sports
Publisher         Nintendo
NA_Sales             41.49
EU_Sales             29.02
JP_Sales              3.77
Other_Sales           8.46
Global_Sales         82.74
Name: 0, dtype: object
# Explore statistics in the year 2006 (highest selling year)
df3 = df[(df['Year'] == 2006)]
df3.describe()

descriptive statistics of 2006 sales

# Plot the results of the previous dataframe (games from 2006) - we can see the year's results were largely carried by Wii Sports
sns.catplot(x="Genre", y="Global_Sales", data=df3, jitter=False).set_xticklabels(rotation=45)

plot of 2006 sales

# We can see 4 outliers in the graph above, so let's get the top 5 games from that dataframe
# The results below show that Nintendo had all top 5 games (3 on the Wii and 2 on the DS)
df3.sort_values(by=['Global_Sales'], ascending=False).head(5)

outliers of 2006 sales

Discussion

The purpose of exploring datasets is to ask questions, answer questions, and discover intelligence that can be used to inform decision making. So, what have we found in this dataset?

Today, we simply explored a publicly-available dataset to see what kind of information it contained. During that exploration, we found that video game sales peaked in 2006. That peak was largely due to Nintendo, who sold the top 5 games in 2006 and has a number of games in the top 10 list for the years 1980-2020. Additionally, the top four platforms by global sales (Wii, NES, GB, DS) are owned by Nintendo.

We didn't explore everything this dataset has to offer, but we can tell from a brief analysis that Nintendo seems to rule sales in the video gaming world. Further analysis could provide insight into which genres, regions, publishers, or world events are correlated with sales.