# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

import numpy as np # linear algebra
import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" 
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
"""
# Video Games Sales Analysis (Beginner)

![VideoGameSales](https://github.com/Henri-debug/Video_Games_Sales/blob/master/Imgs%20for%20README/Capa.png?raw=true)

"""
"""
## Fields

- 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.


## Credits
- [Database Link](https://www.kaggle.com/gregorut/videogamesales)
- [Database Author](https://www.kaggle.com/gregorut)
- [License](https://github.com/GregorUT/vgchartzScrape/blob/master/LICENSE)

# Questions

- Which platform sold the most?
- Which publisher had the most sales and in which genre did it sell the most?
- What was the most successful game?

"""
"""
# Libs
"""
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# Data Extraction
videogames_df = pd.read_csv("../input/videogamesales/vgsales.csv")
videogames_df
"""
# Data Cleaning
"""
videogames_df.info()
videogames_df.describe()
videogames_df.isnull().sum()
videogames_df = videogames_df.dropna()
videogames_df.isnull().sum()
videogames_df.describe()
videogames_df.Year = videogames_df.Year.astype(int)
"""
# Analysis
"""
publisher_salesDF = videogames_df.groupby('Publisher')[['NA_Sales','EU_Sales','JP_Sales','Other_Sales','Global_Sales']].sum()
publisher_salesDF
publisher_salesDF.max()

publisher_salesDF.min()
"""
## Which publisher had the most sales and in which genre did it sell the most?
"""
# Find which publisher earned the most

publisher_salesDF[publisher_salesDF['Global_Sales'] == publisher_salesDF['Global_Sales'].max()]
nintendo_salesDF = videogames_df[videogames_df['Publisher'] == 'Nintendo']
nintendo_salesDF
globalSales_genre = nintendo_salesDF.groupby('Genre')[['Global_Sales']].sum()
globalSales_genre
genre = ['Action','Adventure','Fighting','Misc','Platform','Puzzle','Racing','Role-Playing','Shooter','Simulation','Sports','Strategy']
plt.figure(figsize=(15,10))
sns.barplot(x = globalSales_genre['Global_Sales'], y = genre, palette='inferno')
sns.color_palette("rocket")
plt.title("Nintendo Global Sales", size = 20)
plt.xlabel("Sales(In Millions)",size = 15)
plt.ylabel("Genre", size = 15)
"""
## What was the most successful game?

"""
names_games = videogames_df.groupby(['Name','Year','Publisher','Genre'])[['Global_Sales']].sum()
names_games
names_games.max()
names_games.min()
names_games[names_games['Global_Sales'] == names_games['Global_Sales'].max()]
"""
## Which platform sold the most?
"""
platform_sales = videogames_df.groupby('Platform')[['Global_Sales']].sum()
platform_sales
platforms=['2600','3DO','3DS','DC','DS','GB','GBA','GC','GEN','GG','N64','NES','NG','PC','PCFX','PS','PS2','PS3','PS4','PSP','PSV','SAT','SCD','SNES','TG16','WS','Wii','WiiU','X360','XB','XOne']
#create bar chart
plt.figure(figsize=(15,10))
sns.barplot(x = platform_sales['Global_Sales'], y = platforms, color='#2dfdd4')
plt.title("Platforms Sales", size = 20)
plt.xlabel("Sales(In Millions)",size = 15)
plt.ylabel("Platform", size = 15)