<jupyter_start><jupyter_text>Research Question(s): **-Comparing the sales of different genres in different regions, primarily, North America, Europe, and Japan.  -Looking at the total sales of different genres in these regions, and finding out the most popular genres.  -The analysis also tries to connect genre popularity in these regions with factors such as cultural influence, etc.*****The EDA explores different features about the dataset, and finds some interesting features related to the research question.***<jupyter_code>import pandas as pd
import numpy as np
import seaborn as sns
import matplotlib.pylab as plt<jupyter_output><empty_output><jupyter_text>The piece of code below processes the dataset: ***The dataset produced as a result is clean, and is saved in the processed directory.***<jupyter_code># cleaning the dataset: getting rid of nulls and repeated values
# couldn't use the project_functions module due to import error
# using the piece of code from load_and_clean method in project_functions under the Scripts folder.
# Please also check project_functions.ipynb
dataset_address = 'C:\\Users\\admin\\Desktop\\Uni files\\Term I\\DATA 301\\Project\\course-project-group_6003\\data\\raw\\Gamesales.csv'
data_frame = pd.read_csv(dataset_address)              # original dataset
data_frame.head(7)
# DISPLAYING METHOD CHAINING TO GET A DATASET FREE OF NULLS AND DUPLICATES
df = ( pd.read_csv(dataset_address) 
         .dropna(how = "any")                      # remove null values
         .rename(columns = {"Name" : "Title", 'Year_of_Release' : 'Year Released'})     # rename the first column to Title
         .drop_duplicates()                        # drop duplicates if any
        
     )
df.to_csv('C:\\Users\\admin\\Desktop\\Uni files\\Term I\\DATA 301\\Project\\course-project-group_6003\\data\\processed\\Gamesales_clean.csv')
df.head(3)        # df is free of nulls and duplicates<jupyter_output><empty_output><jupyter_text>Short summary: ***The code below lists a short numerical summary of the dataset.***<jupyter_code># Basic analysis:
print(f'Columns: {df.columns}')                    # printing different columns
print(f'Number of rows and columns: {df.shape}')     
df.describe()                                      # Short summary of the dataset<jupyter_output>Columns: Index(['Title', 'Platform', 'Year Released', 'Genre', 'Publisher', 'NA_Sales',
       'EU_Sales', 'JP_Sales', 'Other_Sales', 'Global_Sales', 'Critic_Score',
       'Critic_Count', 'User_Score', 'User_Count', 'Developer', 'Rating'],
      dtype='object')
Number of rows and columns: (6825, 16)<jupyter_text>The following code tells us the release years of different games in the dataset:<jupyter_code># Year_of_Release column
print(f'Range of years: {df["Year Released"].unique()}')
# The dataset consists of games released from the year 1985 to those released in 2016.<jupyter_output>Range of years: [2006. 2008. 2009. 2005. 2007. 2010. 2013. 2004. 2002. 2001. 2011. 2012.
 2014. 1997. 1999. 2015. 2016. 2003. 1998. 1996. 2000. 1994. 1985. 1992.
 1988.]<jupyter_text>Looking at Japan: ***-The following block of code looks at games released in 2016 in Japan.     -Among the games released in 2016, Role-playing games were found to be the most popular.     -It could be inferred from the plot that the most popular genre in Japan during the period 2016-17 was Role-playing, followed by Action.***<jupyter_code># FOCUSING ON GAMES RELEASED IN 2016, JAPAN
df1 = df[(df["Year Released"] == 2016) & (df['JP_Sales'] > df['NA_Sales']) & (df['JP_Sales'] > df['EU_Sales']) ]    
df1['Genre'].unique()        # DIFFERENT GENRES OF PS4 GAMES RELEASED IN 2016 

japan_sales = df1[['Title', 'Genre', 'JP_Sales', 'NA_Sales', 'EU_Sales']]
japan_sales

# PLOTTING THE GRAPH OF FREQUENCY OF EACH GENRE IN JAPAN GAMES RELEASED IN 2016
sns.countplot(x = 'Genre', data = japan_sales)  
plt.title('Different Genres of 2016 Games - Japan')
plt.xticks(rotation = 90)   
# IT COULD BE INFERRED THAT THE MOST POPULAR GENRE IN JAPAN DURING THE PERIOD 2016-17 WAS ROLE-PLAYING, FOLLOWED BY ACTION.<jupyter_output><empty_output><jupyter_text>Comparing Sports and Action game sales in North America and Europe: ***-The following blocks of code compare Action and Sports game sales in North America and Europe.    -The dataset used for the first plot only takes into account those Sports and Action games which had more sales in North America than in Europe.  -The dataset used for the second plot only takes into account those Sports and Action games which had more sales in Europe than in North America.  -The two plots make us infer that Sports and Action games had more sales in North America than in Europe.***<jupyter_code># COMPARING SPORTS AND ACTION GAME SALES IN NORTH AMERICA AND EUROPE
df2 = df[(((df['Genre'] == 'Sports') | (df['Genre'] == 'Action')) & (df['NA_Sales'] > df['EU_Sales']))]
df3 = df[(((df['Genre'] == 'Sports') | (df['Genre'] == 'Action')) & (df['EU_Sales'] > df['NA_Sales']))]
games_NA = df2[['Title', 'Year Released', 'Genre', 'NA_Sales', 'EU_Sales']]
games_EU = df3[['Title', 'Year Released', 'Genre', 'NA_Sales', 'EU_Sales']]
p1 = sns.countplot(x = 'Genre', data = games_NA)
plt.title("Action and Sport games in North America")
p1
# PLEASE LOOK AT THE NEXT PLOT
# CONTINUED
p2 = sns.countplot(x = 'Genre', data = games_EU)
plt.title("Action and Sport games in Europe")
p2
# THIS MAKES US INFER THAT SPORTS AND ACTION GAMES HAD MORE SALES IN NORTH AMERICA THAN IN EUROPE.
# ON AN AVERAGE, ACTION AND SPORTS GAME SALES IN NORTH AMERICA WERE MORE THAN THAT OF EUROPE.<jupyter_output><empty_output><jupyter_text>Exploring different genres in North America: ***-The dataset used for the second plot only takes into account those Sports and Action games which had more sales in North America than in Europe and Japan.  -The plot below suggests that Action games had more sales in North America as compared to those of Europe and Japan.  -It could also be inferred that Action games were the most popular in North America.***<jupyter_code># GENRES POPULAR IN NORTH AMERICA
df4 = df[((df['NA_Sales'] > df['EU_Sales']) & ((df['NA_Sales'] > df['JP_Sales']) ))]
df4.head(5)
na_genres =  df4[['Title', 'Year Released', 'Genre', 'NA_Sales']]
p3 = sns.countplot(x = 'Genre', data = df4)
plt.title('Different Genres of Games - North America')
plt.xticks(rotation = 90)
p3    
# ACTION GAMES SEEM TO HAVE GREATER SALES IN NORTH AMERICA, AS COMPARED TO THOSE OF EUROPE AND JAPAN.<jupyter_output><empty_output><jupyter_text>The following piece of code generates the total sales of the three most popular game genres in North America during the period 2016-17: ***-A violin plot is also generated for the same.  -In the violin plot below, even though Sports games had the most varrying sales for different games, Action games had the most sales, and therefore must be most popular, as the total sales analysis suggests.***<jupyter_code># COMPARING SALES OF DIFFERENT GENRES IN NORTH AMERICA
na_genres = df[['Title', 'Year Released', 'Genre', 'NA_Sales']]
# ANALYZING SALES FOR THE 3 MOST POPULAR GENRES
na_sports = na_genres[na_genres['Genre'] == 'Sports']
print(f'Total sales of Sports games in North America: {round(na_sports["NA_Sales"].sum(), 1)}    count: {(na_sports["NA_Sales"] > 0).count()}')

na_action = na_genres[na_genres['Genre'] == 'Action']
print(f'Total sales of Action games in North America: {round(na_action["NA_Sales"].sum(), 1)}    count: {(na_action["NA_Sales"]>0).count()}')

na_shooter = na_genres[na_genres['Genre'] == 'Shooter']
print(f'Total sales of Shooter games in North America: {round(na_shooter["NA_Sales"].sum(), 1)}  count: {(na_shooter["NA_Sales"] > 0).count()}')
# COMPARING SALES OF DIFFERENT GENRES IN NORTH AMERICA
sns.violinplot(x = 'Genre', y = 'NA_Sales', data = df)
plt.xticks(rotation = 90)
plt.title("Sales of different genres in North America")
# IT COULD BE INFERRED THAT SPORTS WERE A BIT MORE EXPENSIVE THAN THE REST. A PARTICULAR SPORTS GAME MADE THE MOST SALES.<jupyter_output><empty_output><jupyter_text>Comparing the sales of different genres in Europe: ***The violin plot suggests that the sport games were more variable than the rest gof the genres.***<jupyter_code># COMPARING SALES OF DIFFERENT GENRES IN EUROPE
sns.violinplot(x = 'Genre', y = 'EU_Sales', data = df)
plt.title("Sales of different genres in Europe")
plt.xticks(rotation = 90)
# IT COULD BE SAID THAT SPORTS GAMES WERE MORE EXPENSIVE THAN THE REST.<jupyter_output><empty_output><jupyter_text>Looking at game sales in other regions: ***-This compares the sales of different game genres in regions other than North America, Europe, and Japan.  -Action game sales were more variable, followed by Sports and Racing.***<jupyter_code># COMPARING SALES OF DIFFERENT GENRES IN REGIONS OTHER THAN NORTH AMERICA, EUROPE AND JAPAN
sns.violinplot(x = 'Genre', y = 'Other_Sales', data = df)
plt.title("Sales of different genres in Elsewhere")
plt.xticks(rotation = 90)<jupyter_output><empty_output><jupyter_text>Comparing Sales of Action games in North America and Elsewhere (excluding Europe and Japan): ***-Total sales of Action games in North America were more than thrice that of other regions (excluding Europe and Japan).  -A plot is generated again for reference.***<jupyter_code># COMPARING SALES OF ACTION GAMES IN NORTH AMERICA AND REGIONS EXCLUDING JAPAN AND EUROPE
sales_elsewhere = df[['Title', 'Genre', 'Year Released', 'Platform', 'Other_Sales']]
elsewhere_action = sales_elsewhere[sales_elsewhere['Genre'] == 'Action']
print(f'Total sales of Action games in Elsewhere: {round(elsewhere_action["Other_Sales"].sum(), 1)}')
na_action = na_genres[na_genres['Genre'] == 'Action']
print(f'Total sales of Action games in North America: {round(na_action["NA_Sales"].sum(), 1)}')
# TOTAL SALES OF ACTION GAMES IN NORTH AMERICA WERE MORE THAN 3 TIMES THAT OF OTHER REGIONS (EXCLUDING EUROPE AND JAPAN)!
# POPULAR GENRE IN NORTH AMERICA
df5 = df[df['NA_Sales'] > 0]
df5 = df5[['Title', 'Year Released', 'Genre', 'NA_Sales']]
p4 = sns.countplot(x = 'Genre', data = df5)
plt.title('Different Genres of Games - North America')
plt.xticks(rotation = 90)
p4    
# ACTION GENRE SEEMS TO BE THE MOST POPULAR -- ALSO JUSTIFIED BY SALES<jupyter_output><empty_output><jupyter_text>***-Overall, Action games were found to be popular in North America, and generated more sales in total than in other regions including Europe and Japan.  -The following code compares the sales of Action games globally with that of North America, and notices an interesting observation.  -The total sales of Action games in North America constituted about 50% of the total sales globally.***<jupyter_code># COMPARING ACTION GAME SALES WITH GLOBAL SALES
games = df[['Title', 'Year Released', 'Genre', 'NA_Sales', 'Global_Sales']]
action_games = games[games['Genre'] == 'Action']
print(f'Total action game sales in NA: {action_games["NA_Sales"].sum()}')
print(f'Total action game sales globally: {action_games["Global_Sales"].sum()}')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10975278456941048, 'fraction_numerical': 0.020465453228289413, 'mean_word_length': 4.905882352941177, 'pattern_counts': {'":': 0, '<': 47, '<?xml version=': 0, '>': 57, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '12', 'dir': 'jupyter-structured-clean-dedup', 'id': '436915', 'license': 'MIT', 'n_tokens_mistral': 3800, 'n_tokens_neox': 3348, 'n_words': 1310, 'path': 'Analysis/Neilansh/Milestone 2_task 4.ipynb', 'repo_name': 'NeilanshTriesToCode/Python-Data-Analysis', 'size': '11043'}