Jovian
⭐️
Sign In

Video Game Sales What Can We See From The Numbers ?

Video game is always related to our childhood. We played game when we're small and even when we're already an adult. But is the industry doing well these day ? We can analyze the video game sale dataset with graphs visualization to get some insight about that.

The dataset is taken from https://www.kaggle.com/rishidamarla/video-game-sales

Libraries used in project :

  • Pandas : a software library written for the Python programming language for data manipulation and analysis
  • Numpy : a library for the Python programming language, adding support for large, multi-dimensional arrays and matrices, along with a large collection of high-level mathematical functions to operate on these arrays.
  • Matplotlib : a plotting library for the Python programming language and its numerical mathematics extension NumPy.
  • Seaborn : a Python data visualization library based on matplotlib. It provides a high-level interface for drawing attractive and informative statistical graphics.

Thanks Jovian for the course project.

How to run the code

This is an executable Jupyter notebook hosted on Jovian.ml, a platform for sharing data science projects. You can run and experiment with the code in a couple of ways: using free online resources (recommended) or on your own computer.

Option 1: Running using free online resources (1-click, recommended)

The easiest way to start executing this notebook is to click the "Run" button at the top of this page, and select "Run on Binder". This will run the notebook on mybinder.org, a free online service for running Jupyter notebooks. You can also select "Run on Colab" or "Run on Kaggle".

Option 2: Running on your computer locally
  1. Install Conda by following these instructions. Add Conda binaries to your system PATH, so you can use the conda command on your terminal.

  2. Create a Conda environment and install the required libraries by running these commands on the terminal:

conda create -n zerotopandas -y python=3.8 
conda activate zerotopandas
pip install jovian jupyter numpy pandas matplotlib seaborn opendatasets --upgrade
  1. Press the "Clone" button above to copy the command for downloading the notebook, and run it on the terminal. This will create a new directory and download the notebook. The command will look something like this:
jovian clone notebook-owner/notebook-id
  1. Enter the newly created directory using cd directory-name and start the Jupyter notebook.
jupyter notebook

You can now access Jupyter's web interface by clicking the link that shows up on the terminal or by visiting http://localhost:8888 on your browser. Click on the notebook file (it has a .ipynb extension) to open it.

Downloading the Dataset

Firstly We need to download the dataset to use. The link is already provided in the description above. You can also find a lot of interesting datasets on Kaggle

In [1]:
!pip install jovian opendatasets --upgrade --quiet

Let's begin by downloading the data, and listing the files within the dataset.

In [1]:
# Change this
dataset_url = 'https://www.kaggle.com/rishidamarla/video-game-sales' 

The downloader will need to use ur username and apikey (generated in ur profile account on Kaggle) so firstly you should probably regis an account on Kaggle.

In [2]:
import opendatasets as od
od.download(dataset_url)
Please provide your Kaggle credentials to download this dataset. Learn more: http://bit.ly/kaggle-creds Your Kaggle username: akariiiii Your Kaggle Key: ········
100%|██████████| 476k/476k [00:00<00:00, 83.7MB/s]
Downloading video-game-sales.zip to ./video-game-sales

The dataset has been downloaded and extracted.

In [3]:
# Change this
data_dir = './video-game-sales'
In [4]:
import os
os.listdir(data_dir)
Out[4]:
['Video_Games.csv']

Let us save and upload our work to Jovian before continuing.

In [6]:
project_name = "data-analysis-of-video-game-sales"
In [7]:
!pip install jovian --upgrade -q
In [8]:
import jovian
In [9]:
jovian.commit(project=project_name)
[jovian] Attempting to save notebook.. [jovian] Please enter your API key ( from https://jovian.ml/ ): API KEY: ········ [jovian] Updating notebook "indexkyou/data-analysis-of-video-game-sales" on https://jovian.ml/ [jovian] Uploading notebook.. [jovian] Capturing environment.. [jovian] Committed successfully! https://jovian.ml/indexkyou/data-analysis-of-video-game-sales

Data Preparation and Cleaning

Firstly we should load the dataset into Pandas data frame and take a look what can we get with this dataset.

In [14]:
import pandas as pd
In [15]:
game_sales_df = pd.read_csv('./video-game-sales/Video_Games.csv')
In [16]:
game_sales_df
Out[16]:
Pretty cool we have 16719 rows equal to 16719 game titles here. We should probably check out the columns and info to see if this dataset is already workable
In [17]:
game_sales_df.columns
Out[17]:
Index(['Name', 'Platform', 'Year_of_Release', 'Genre', 'Publisher', 'NA_Sales',
       'EU_Sales', 'JP_Sales', 'Other_Sales', 'Global_Sales', 'Critic_Score',
       'Critic_Count', 'User_Score', 'User_Count', 'Developer', 'Rating'],
      dtype='object')
In [18]:
game_sales_df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 16719 entries, 0 to 16718 Data columns (total 16 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Name 16717 non-null object 1 Platform 16719 non-null object 2 Year_of_Release 16450 non-null float64 3 Genre 16717 non-null object 4 Publisher 16665 non-null object 5 NA_Sales 16719 non-null float64 6 EU_Sales 16719 non-null float64 7 JP_Sales 16719 non-null float64 8 Other_Sales 16719 non-null float64 9 Global_Sales 16719 non-null float64 10 Critic_Score 8137 non-null float64 11 Critic_Count 8137 non-null float64 12 User_Score 10015 non-null object 13 User_Count 7590 non-null float64 14 Developer 10096 non-null object 15 Rating 9950 non-null object dtypes: float64(9), object(7) memory usage: 2.0+ MB

Look at the info we can see that :

  • Not every game is rating and get critic score.
  • Year of release | Platform doesnt match the name index.

We should try remove nun object for a better dataframe.

In [22]:
game_sales_df.drop(game_sales_df[game_sales_df.Year_of_Release.isnull()].index, inplace = True)
game_sales_df.drop(game_sales_df[game_sales_df.Name.isnull()].index, inplace = True)
game_sales_df.drop(game_sales_df[game_sales_df.Publisher.isnull()].index, inplace = True)
game_sales_df.info()
<class 'pandas.core.frame.DataFrame'> Int64Index: 16416 entries, 0 to 16718 Data columns (total 16 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 Name 16416 non-null object 1 Platform 16416 non-null object 2 Year_of_Release 16416 non-null float64 3 Genre 16416 non-null object 4 Publisher 16416 non-null object 5 NA_Sales 16416 non-null float64 6 EU_Sales 16416 non-null float64 7 JP_Sales 16416 non-null float64 8 Other_Sales 16416 non-null float64 9 Global_Sales 16416 non-null float64 10 Critic_Score 7982 non-null float64 11 Critic_Count 7982 non-null float64 12 User_Score 9837 non-null object 13 User_Count 7461 non-null float64 14 Developer 9904 non-null object 15 Rating 9767 non-null object dtypes: float64(9), object(7) memory usage: 2.1+ MB

Ok that dataframe seems good enough. We should take a closer look at the description.

In [23]:
game_sales_df.describe()
Out[23]:

So we have around 16450 game titles that was sold between 1980 and 2020. NA seems like the biggest market to sell game.

In [24]:
import jovian
In [25]:
jovian.commit()
[jovian] Attempting to save notebook.. [jovian] Updating notebook "indexkyou/data-analysis-of-video-game-sales" on https://jovian.ml/ [jovian] Uploading notebook.. [jovian] Capturing environment.. [jovian] Committed successfully! https://jovian.ml/indexkyou/data-analysis-of-video-game-sales

Exploratory Analysis and Visualization

At first look the dataframe is already sorted by Global_Sales. But for better viewer we should try creating a few graph.

Let's begin by importingmatplotlib.pyplot and seaborn.

In [26]:
import seaborn as sns
import matplotlib
import matplotlib.pyplot as plt
%matplotlib inline

sns.set_style('darkgrid')
matplotlib.rcParams['font.size'] = 13
matplotlib.rcParams['figure.figsize'] = (36, 20)
matplotlib.rcParams['figure.facecolor'] = '#00000000'

First, We should see the total sales of games each year. It helps us know when video game is declined and when is it popular.

In [27]:
sns.countplot('Year_of_Release', data = game_sales_df)
plt.title('Total game sale each year')
plt.show()

Seems like we dont have much data from 2017 to 2020 let remove them and try using another graph for better view.

In [52]:
game_sales_df.drop(game_sales_df[game_sales_df.Year_of_Release > 2016].index, inplace = True)

sales_df = game_sales_df.groupby('Year_of_Release', as_index = False).sum()

x = sales_df['Year_of_Release']
y = sales_df['Global_Sales']

plt.figure(figsize=(20,10), dpi= 60)
plt.plot(x,y, label = 'Sales', color = 'green')
plt.xlabel('Year')
plt.ylabel('Sales')
plt.title('Total game sale each year')
plt.legend()
plt.show()

Let add other sales area as well like NA | EU | JP

In [65]:
sales_df
Out[65]:
In [67]:
x = sales_df['Year_of_Release']
na = sales_df['NA_Sales']
eu = sales_df['EU_Sales']
jp = sales_df['JP_Sales']
total = sales_df['Global_Sales']

plt.title('Sales comparison between area and global')
plt.plot(x,total, label = 'Global')
plt.plot(x,na, label = 'US')
plt.plot(x,eu, label = 'EU')
plt.plot(x,jp, label = 'JP')
plt.legend(bbox_to_anchor =(1, 1))
Out[67]:
<matplotlib.legend.Legend at 0x7ff838d6ce50>

We can see that US is the largest market follow by EU and JP. JP is pretyy consistent and doesnt seem to be declined that much. In 2008 and 2009 video game was explored in popular so we should take a look at the game list in these year.

In [68]:
list_games_2008 = game_sales_df.loc[game_sales_df['Year_of_Release'] == 2008]
list_games_2008.sort_values('Global_Sales',ascending = False).head(10)
Out[68]:
In [69]:
list_games_2009 = game_sales_df.loc[game_sales_df['Year_of_Release'] == 2009]
list_games_2009.sort_values('Global_Sales',ascending = False).head(10)
Out[69]:

In 2008 and 2009, the most popular game is from Wii platform. That's pretty interesting let see the pie graph for platform (We should combine two dataframe as well)

In [70]:
combine_list = list_games_2008.append(list_games_2009)
platform_counts = combine_list.Platform.value_counts()
platform_counts
Out[70]:
DS      895
Wii     607
X360    318
PS3     300
PS2     287
PSP     261
PC      183
DC        1
XB        1
Name: Platform, dtype: int64
In [72]:
platform_counts = platform_counts.remove(platform_counts  < 2)
plt.figure(figsize=(24,12))
plt.pie(platform_counts, labels=platform_counts.index, autopct='%1.1f%%', startangle=180);
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-72-888ebe9ac893> in <module> ----> 1 platform_counts.drop(platform_counts < 2) 2 plt.figure(figsize=(24,12)) 3 plt.pie(platform_counts, labels=platform_counts.index, autopct='%1.1f%%', startangle=180); /srv/conda/envs/notebook/lib/python3.8/site-packages/pandas/core/series.py in drop(self, labels, axis, index, columns, level, inplace, errors) 4495 dtype: float64 4496 """ -> 4497 return super().drop( 4498 labels=labels, 4499 axis=axis, /srv/conda/envs/notebook/lib/python3.8/site-packages/pandas/core/generic.py in drop(self, labels, axis, index, columns, level, inplace, errors) 3882 for axis, labels in axes.items(): 3883 if labels is not None: -> 3884 obj = obj._drop_axis(labels, axis, level=level, errors=errors) 3885 3886 if inplace: /srv/conda/envs/notebook/lib/python3.8/site-packages/pandas/core/generic.py in _drop_axis(self, labels, axis, level, errors) 3916 new_axis = axis.drop(labels, level=level, errors=errors) 3917 else: -> 3918 new_axis = axis.drop(labels, errors=errors) 3919 result = self.reindex(**{axis_name: new_axis}) 3920 /srv/conda/envs/notebook/lib/python3.8/site-packages/pandas/core/indexes/base.py in drop(self, labels, errors) 5276 if mask.any(): 5277 if errors != "ignore": -> 5278 raise KeyError(f"{labels[mask]} not found in axis") 5279 indexer = indexer[~mask] 5280 return self.delete(indexer) KeyError: '[False False False False False False False True True] not found in axis'

Overall DS and Wii did the best in these year. Nintendo was really good back in time. We should properly check how Nintendo is doing up until now.

In [91]:
nitendo_df = game_sales_df.loc[game_sales_df['Publisher'] == 'Nintendo']
nitendo_df = nitendo_df.groupby('Year_of_Release').count()
nitendo_df = nitendo_df['Global_Sales']

plt.title("Nintendo sales")
sns.barplot(nitendo_df.index, nitendo_df, color="green");

Is Nitendo the top publisher ? Let check the top 15 publishers

In [85]:
top_publishers = game_sales_df.Publisher.value_counts().head(15)
top_publishers
Out[85]:
Electronic Arts                           1344
Activision                                 976
Namco Bandai Games                         935
Ubisoft                                    930
Konami Digital Entertainment               825
THQ                                        712
Nintendo                                   700
Sony Computer Entertainment                686
Sega                                       631
Take-Two Interactive                       421
Capcom                                     381
Atari                                      351
Tecmo Koei                                 348
Square Enix                                232
Warner Bros. Interactive Entertainment     220
Name: Publisher, dtype: int64
In [83]:
plt.figure(figsize=(12,6))
plt.xticks(rotation=75)
sns.barplot(top_publishers.index, top_publishers);

The most popular genre

In [ ]:
 

Let us save and upload our work to Jovian before continuing

In [106]:
import jovian
In [107]:
jovian.commit()
[jovian] Attempting to save notebook.. [jovian] Updating notebook "indexkyou/data-analysis-of-video-game-sales" on https://jovian.ml/ [jovian] Uploading notebook.. [jovian] Capturing environment.. [jovian] Committed successfully! https://jovian.ml/indexkyou/data-analysis-of-video-game-sales

Asking and Answering Questions

TODO - write some explanation here.

Instructions (delete this cell)

  • Ask at least 5 interesting questions about your dataset
  • Answer the questions either by computing the results using Numpy/Pandas or by plotting graphs using Matplotlib/Seaborn
  • Create new columns, merge multiple dataset and perform grouping/aggregation wherever necessary
  • Wherever you're using a library function from Pandas/Numpy/Matplotlib etc. explain briefly what it does
Q1: TODO - ask a question here and answer it below
In [ ]:
 
In [ ]:
 
In [ ]:
 
Q2: TODO - ask a question here and answer it below
In [ ]:
 
In [ ]:
 
In [ ]:
 
Q3: TODO - ask a question here and answer it below
In [ ]:
 
In [ ]:
 
In [ ]:
 
Q4: TODO - ask a question here and answer it below
In [ ]:
 
In [ ]:
 
In [ ]:
 
Q5: TODO - ask a question here and answer it below
In [ ]:
 
In [ ]:
 
In [ ]:
 

Let us save and upload our work to Jovian before continuing.

In [92]:
import jovian
In [93]:
jovian.commit()
[jovian] Attempting to save notebook.. [jovian] Updating notebook "indexkyou/data-analysis-of-video-game-sales" on https://jovian.ml/ [jovian] Uploading notebook.. [jovian] Capturing environment.. [jovian] Committed successfully! https://jovian.ml/indexkyou/data-analysis-of-video-game-sales

Inferences and Conclusion

TODO - Write some explanation here: a summary of all the inferences drawn from the analysis, and any conclusions you may have drawn by answering various questions.

In [30]:
import jovian
In [31]:
jovian.commit()
[jovian] Attempting to save notebook.. [jovian] Updating notebook "aakashns/zerotopandas-course-project-starter" on https://jovian.ml/ [jovian] Uploading notebook.. [jovian] Capturing environment.. [jovian] Committed successfully! https://jovian.ml/aakashns/zerotopandas-course-project-starter

References and Future Work

TODO - Write some explanation here: ideas for future projects using this dataset, and links to resources you found useful.

Submission Instructions (delete this cell)

(Optional) Write a blog post

In [88]:
import jovian
In [89]:
jovian.commit()
[jovian] Attempting to save notebook.. [jovian] Updating notebook "indexkyou/data-analysis-of-video-game-sales" on https://jovian.ml/ [jovian] Uploading notebook.. [jovian] Capturing environment.. [jovian] Committed successfully! https://jovian.ml/indexkyou/data-analysis-of-video-game-sales
In [ ]: