Beginner EDA on Video Game Sales - Kaggle Dataset
Tags: datascience, analytics, python, jupyter
Published: 2021-11-12 11:28:29

## Introduction:
Data Science has become a booming field recent couple of years. It is the most hot topic right now besides AI/ML and Deep Learning. Since, the data is in abundance and the Big Companies need to get to know their crowd for maximizing their profits, Data Analysis and Data Science concepts are applied. 
 
In any ML project, the steps are followed like this:
1] Data Collection
2] EDA
3] Feature Engineering
4] Feature Selection
5] Outlier
6] Model Creation 
7 Deployment
I am here to talk about the EDA that I have done in the Video Game Sales data set in Kaggle.
Exploratory Data Analysis is the most crucial part of the Data Science project. It can ***"Make Or Break"*** your project as most of the important insights as well as predictions can be done using EDA concepts.

I have applied Concepts of EDA on Video Game Sales Data set of Kaggle. 
Here's the link to my Kaggle Notebook: 
[Basic EDA on Video Game Sales - Kaggle](kaggle.com/siddheshshankarcoder/eda-with-video-game-sales-data/notebook)

## Let's start the project:
Always we need to know what our data set is and what all libraries the project needs.
There are 16,598 records. 2 records were dropped due to incomplete information.

It contains around
The video Game Sales data includes 11 fields/columns. They are: 
- Rank -> It shows the rank of the game.
- Name -> Name of the game.
- Platform -> The platform on which it was published.
- Year -> The year at which the game was first released.
- Genre -> The genre or topic on which the game is based.
- Publisher -> The publisher who published the game in the gaming market.
- NA_Sales -> The Sales of the game in the North American Gaming Market (in millions)
- EU_Sales -> The Sales of the game in the European Union Gaming Market (in millions)
- JP_Sales -> The Sales of the game in the Japanese Gaming Market (in millions)
- Other_Sales -> The Sales of the game in the other Gaming Markets in Asia, Arab, Russia etc. (in millions)
- Global_Sales -> The Total Sales of the game in the Gaming Market (in millions)

So, ***we import the libraries:***

```python
import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)
import matplotlib.pyplot as plt # for data visualization
%matplotlib inline
import seaborn as sns # for advanced data visualizations
```

After importing the libraries, we ***import the data set:***

```python
vgSales = pd.read_csv("../input/videogamesales/vgsales.csv")
vgSales.head()
``` 
Here, the data file was a .csv file i.e. a comma separated value file.
```python
VariableName = pd.read_csv("file_name.csv")
```

Comma Separated Values means that, the values in the file or records is separated by comma i.e. ','.
Here, to see the first 5 records of the data frame we have created using Pandas Library, I have used .head() function. 
Now after importing the data set successfully, we are ready to go for the data cleaning. 

To get information from the data about its column names, its data types, Null Count etc., we use .info() and .isna().sum():
```python
vgSales.info()
vgSales.isna().sum()
```
We can observe that the **Year** column is having 271 NA records and the **Publisher** column is having 58 NA records, which makes a total of 329 NA records in the data set.
Hence, we need to remove these before visualization and taking useful insights from them.

Apart from the NA values worrying us, we can also find the other anomalies present in the data set.

This data set holds records till 2017th Year. But when we try to find the maximum value of the records in **Year** column, I get a crucial anomaly.

```python
print("Max Year Value: ", vgSales['Year'].max())
```
By this function code we can get the max value in the column we want. This showed that the **Year** column had maximum value 2020. Then I mined out that record to investigate carefully. 
```python
maxEntry = vgSales['Year'].idxmax()
vgSales.iloc[maxEntry]
```
I observed that it gave a game record that wasn't released in 2020 Year but it was actually published by Ubisoft on 2009. This was the output.
![Output](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/2bjj1bxu3b9cx91i6vi2.png)

I then replaced the value with the correct one.
```python
vgSales["Year"] = vgSales["Year"].replace(2020.0, 2009.0)
print("Max Year Value: ", vgSales["Year"].max())
```
Now, this was just one anomaly. I found out that there were many anomalies like these. So, decided to replace them with the year 2009 as the visualization of that data showed that 2009 was the year in which most of the games were produced or released. 
```python
YearAnamoly = vgSales[vgSales['Year'].isnull()]['Name'].unique()
print("The year records having such anomaly: ", len(YearAnamoly))
```
There were 233 such records.
```python
plt.figure(figsize = (20,20))
plt.bar(vgSales["Year"].value_counts().index, vgSales["Year"].value_counts())
plt.title("The most games produced in a specific year")
plt.show()
```
![The most games produced in the year](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6mip7kfkieylyeacqm3w.png)

```python
vgSales['Year'] = vgSales['Year'].fillna(2009.0)
vgSales['Year'].isnull().sum()
```
After this all the NA values were eradicated from **Year** column. I then converted the Year column Data Type which was float64 to int64 like this:
```python
vgSales['Year'] = vgSales['Year'].astype('int64')
```
I then removed the 58 NA Records in Publisher because it won't affect the visualization as it was an unnecessary noise in the data using .dropna() function.

After anomalies and NA record cleaning I thought of removing the Skewness of columns that are numeric like **NA_Sales**, **EU_Sales**, **JP_Sales**, **Other_Sales**, **Global_Sales** etc.
```python
print("The Skew Count of NA_Sales Column is:",vgSales["NA_Sales"].skew())
print("The Skew Count of EU_Sales Column is:",vgSales["EU_Sales"].skew())
print("The Skew Count of JP_Sales Column is:",vgSales["JP_Sales"].skew())
print("The Skew Count of Other_Sales Column is:",vgSales["Other_Sales"].skew())
```
![Skewness Output](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/4dvb3ojgvqmsc735ksrq.png)
This was the output which showed all these columns are highly positively skewed.
So, we are normalizing the data with the help of Square Root Normalization Method.
```python
vgSales["NA_Sales"] = vgSales["NA_Sales"]**(1/2)
vgSales["EU_Sales"] = vgSales["EU_Sales"]**(1/2)
vgSales["JP_Sales"] = vgSales["JP_Sales"]**(1/2)
vgSales["Other_Sales"] = vgSales["Other_Sales"]**(1/2)
vgSales["Global_Sales"] = vgSales["NA_Sales"] + vgSales["EU_Sales"] + vgSales["JP_Sales"] + vgSales["Other_Sales"]
```

Now, the cleaning and normalization of data was over and Exploratory Data Analysis and Visualization started.

## Exploratory Data Analysis and Visualization:

### To get to know which genre sold the most globally:
```python
vgSales[["Genre","Global_Sales"]].groupby("Genre").sum()
```

![which genre sold the most globally](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/sb0x3h468q2uuwy6zr2h.png)
The Global Sales specific to Genre was done with the help of .groupby() function.
***The most sold genre of games globally is Action Genre. The second highest selling genre globally is Sports Genre.***

### To get the most games produced in a specific Gaming Platform:
```python 
plt.figure(figsize = (20,20))
plt.bar(vgSales["Platform"].value_counts().index, vgSales["Platform"].value_counts())
plt.title("Most Games produced in Specific Gaming Platform")
plt.show()
```
![the most games produced in a specific Gaming Platform](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cp2srqa5j66hhb4ns36b.png)

***We can see that DS and PS2 are tied for the top spot in this.***

## Conclusion:
With this, I did the basic EDA of this data set. 
Here is my Linkedin Profile: 
[Siddhesh Shankar](https://www.linkedin.com/in/siddhesh-shankar-b94711210/)
Here is my github repo link:
[SiddheshCodeMaster](https://github.com/SiddheshCodeMaster/EDA-with-Video-Game-Sales---Kaggle)

Happy Data Cleaning ! Happy Exploration ! Happy Learning !