Video Game Sales電子遊戲銷售分析
- 定義問題:
-
特徵分析:
- 1.遊戲平臺分析
- 2.遊戲類型分析
- 3.地區對比
-
預測分析:
- 未來的銷售趨勢預測
# 導包
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
from pyecharts import options as opts
from pyecharts.charts import Pie
from pyecharts import options as opts
from pyecharts.charts import Bar
plt.style.use('seaborn')
plt.rcParams['font.sans-serif']=['Simhei'] #顯示中文,解決圖中無法顯示中文的問題
plt.rcParams['axes.unicode_minus']=False #設置顯示中文後,負號顯示受影響。解決座標軸上亂碼問題
數據清洗
# 導入數據
data = pd.read_csv("vgsales.csv")
# 查看數據結構,發現Year,Publisher等項是有空值的
print("行數 : ", data.shape[0])
print("列數 : ", data.shape[1])
print("\n特徵數量 : \n", data.columns.tolist())
print("\n缺失值 : \n", data.isnull().sum())
print("\n唯一值 : \n", data.nunique())
行數 : 16598
列數 : 11
特徵數量 :
['Rank', 'Name', 'Platform', 'Year', 'Genre', 'Publisher', 'NA_Sales', 'EU_Sales', 'JP_Sales', 'Other_Sales', 'Global_Sales']
缺失值 :
Rank 0
Name 0
Platform 0
Year 271
Genre 0
Publisher 58
NA_Sales 0
EU_Sales 0
JP_Sales 0
Other_Sales 0
Global_Sales 0
dtype: int64
唯一值 :
Rank 16598
Name 11493
Platform 31
Year 39
Genre 12
Publisher 578
NA_Sales 409
EU_Sales 305
JP_Sales 244
Other_Sales 157
Global_Sales 623
dtype: int64
# 數據體量還是比較大的,這裏就直接刪除了空值
data.dropna(inplace=True)
# 重置下索引
data.reset_index(drop=True,inplace=True)
data.head()
Rank | Name | Platform | Year | Genre | Publisher | NA_Sales | EU_Sales | JP_Sales | Other_Sales | Global_Sales | |
---|---|---|---|---|---|---|---|---|---|---|---|
0 | 1 | Wii Sports | Wii | 2006.0 | Sports | Nintendo | 41.49 | 29.02 | 3.77 | 8.46 | 82.74 |
1 | 2 | Super Mario Bros. | NES | 1985.0 | Platform | Nintendo | 29.08 | 3.58 | 6.81 | 0.77 | 40.24 |
2 | 3 | Mario Kart Wii | Wii | 2008.0 | Racing | Nintendo | 15.85 | 12.88 | 3.79 | 3.31 | 35.82 |
3 | 4 | Wii Sports Resort | Wii | 2009.0 | Sports | Nintendo | 15.75 | 11.01 | 3.28 | 2.96 | 33.00 |
4 | 5 | Pokemon Red/Pokemon Blue | GB | 1996.0 | Role-Playing | Nintendo | 11.27 | 8.89 | 10.22 | 1.00 | 31.37 |
特徵分析
# 做一個平臺和遊戲類型的頻次交叉表來看一下,平臺的遊戲類型分佈情況
Plat_Genre = pd.crosstab(data.Platform,data.Genre)
Plat_Genre_sum = Plat_Genre.sum(axis=1).sort_values(ascending = False)
#平臺的銷量分佈情況
Plat_Global_Sales = data.groupby('Platform')['Global_Sales'].sum().sort_values(ascending = False)
#遊戲類型銷量分佈情況
Genre_Global_Sales = data.groupby('Genre')['Global_Sales'].sum().sort_values(ascending = False)
# 可視化
f,ax = plt.subplots(1,3,figsize=(25,8),dpi=100)
sns.barplot(Plat_Genre_sum.values,Plat_Genre_sum.index,ax=ax[0])
ax[0].set_title('Platform_Genre')
sns.barplot(Plat_Global_Sales.values,Plat_Global_Sales.index,ax=ax[1])
ax[1].set_title('Platform_Global_Sales')
sns.barplot(Genre_Global_Sales.values,Genre_Global_Sales.index,ax=ax[2])
ax[2].set_title('Genre_Global_Sales')
plt.show()
- 在總銷量方面,PS2,PS2,psp(索尼);DS, Wii(任天堂),兩家遊戲平臺佔據領頭羊位置,x360(微軟),在第五名的位置緊跟Wii(任天堂)。
- 在平臺覆蓋遊戲種類方面,PS2,PS2,psp(索尼);x360(微軟),包含遊戲種類較爲豐富,DS,Wii(任天堂),的遊戲種類也緊隨其後沒有拉開較大位置。
- 在遊戲種類方面動作類,運動類,射擊類深受玩家歡迎
#接着在來看看地區和遊戲種類的關係
Genre_gp_sum = data.groupby('Genre').sum()
x= Genre_gp_sum.index.tolist()
Genre_NA = Genre_gp_sum['NA_Sales'].round().tolist()
Genre_EU = Genre_gp_sum['EU_Sales'].round().tolist()
Genre_JP = Genre_gp_sum['JP_Sales'].round().tolist()
Genre_Other = Genre_gp_sum['Other_Sales'].round().tolist()
bar = Bar()
bar.add_xaxis(x).add_yaxis("NA_Sales", Genre_NA).add_yaxis(
"EU_Sales",Genre_EU
).add_yaxis("JP_Sales", Genre_JP).add_yaxis("Other_Sales", Genre_Other).set_global_opts(
title_opts=opts.TitleOpts(title="地區銷量柱狀圖"),
yaxis_opts=opts.AxisOpts(name="銷量"),
xaxis_opts=opts.AxisOpts(name="遊戲類型",axislabel_opts=opts.LabelOpts(interval=0,rotate=-45)),
).render('地區銷量柱狀圖.html')
未來銷售趨勢預測
#各地區-時間-銷量
region = ['NA_Sales','EU_Sales','JP_Sales','Other_Sales','Global_Sales']
region_sales_sum =pd.pivot_table(data,index='Year',values=region,aggfunc='sum')
plt.figure(figsize=(15,8))
sns.lineplot(data=region_sales_sum)
plt.title('地區銷量發展趨勢')
Text(0.5, 1.0, '地區銷量發展趨勢')
- 可以看出從1995 開始直至2008年左右,整個市場有一個上升趨勢,之後便開始下降,到2020年已經幾乎消失滅跡。
# 2011-2016
new_data=data[(2004<data.Year) & (data.Year<2011)]
plt.figure(figsize=(15,10))
sns.catplot(x="Year",y="Global_Sales",kind="bar",
hue="Platform",
data=new_data,
edgecolor=None,
palette='colorblind',
height=8, aspect=14/8,ci=None)
plt.show()
<Figure size 1080x720 with 0 Axes>
- 2005-2010年度的總計銷售分佈情況,可以看出2006年是任天堂的巔峯時刻