主机游戏销售数据分析练习
这份数据集是一张包含销量超过10万份的电视游戏清单,数据来自vgcharts.com
指标分析流程:
数据读取与预处理
import numpy as np
import pandas as pd
df = pd.read_csv(r'C:/Users/Administrator/Desktop/vgsales.csv')
df.head(10)
字段名解释:
Rank:排名
Name:游戏名
Platform:游戏发行平台
Year:发布时间
Genre:游戏类别
Publisher:发行商
NA_Sales:北美区销量(百万)
EU_Sales:欧洲区销量(百万)
JP_Sales:日本区销量(百万)
Other_Sales:其他区销量(百万)
Global_Sales:全球总销量(百万)
df.info()
# 缺失值处理
df.isnull().sum(axis = 0)
数据缺失值不多,直接删除缺失值所在行
df = df.dropna()
df.info()
# 数据类型转换
df['Year'] = df['Year'].astype('int')
df.info()
# 观察异常值并排除
np.unique(df['Year'])
df = df[df['Year'] != 2020]
np.unique(df['Year'])
发行商角度
排名前10各发行商发布游戏占比
df_publisher = df.pivot_table(index = 'Publisher',
values = 'Name',
aggfunc = {'Name':'count'}
)
df_publisher.rename(columns = {'Name':'amount'}, inplace = True)
top10_publisher = df_publisher.sort_values(by = 'amount', ascending = False)[:10]
top10_publisher
# 排名前10发行商
other_publisher_amount = df_publisher['amount'].count() - top10_publisher['amount'].count()
top10_publisher.reset_index(inplace = True)
top10_publisher
# 排名10以外的发行商
others_amount = {'Publisher':'others',
'amount':[other_publisher_amount]}
others = pd.DataFrame(others_amount)
others
top10_others = pd.DataFrame(columns = [‘Publisher’,‘amount’], index = [‘0’,‘1’])
top10_others.iloc[0,0] = ‘top10’
top10_others.iloc[0,1] = top10_publisher[‘amount’].sum()
top10_others.iloc[1,:] = others.iloc[0,:]
top10_others
绘制饼图,查看各发行商发行游戏数量占比
import matplotlib.pyplot as plt
plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签
plt.rcParams['axes.unicode_minus']=False #用来正常显示负号
import warnings
warnings.filterwarnings("ignore")
fig = plt.figure(figsize = (15,15))
ax1 = fig.add_subplot(1, 2, 1)
plt.pie(top10_others['amount'], labels = top10_others['Publisher'], autopct = '%1.2f%%')
plt.title('发行量top10发行商所占市场份额图')
ax2 = fig.add_subplot(1, 2, 2)
plt.pie(top10_publisher['amount'], labels = top10_publisher['Publisher'], autopct = '%1.2f%%')
plt.title('发行量top10发行商份额图')
最受欢迎游戏发行商排名
most_popular_publisher = df.pivot_table(index = 'Publisher',
values = 'Global_Sales',
aggfunc = {'Global_Sales':'sum'}
)
most_popular_publisher.sort_values(by ='Global_Sales', ascending = False, inplace = True)
most_popular_publisher
# 最受欢迎排名前十
top10_popular = most_popular_publisher.iloc[:10,:]
top10_popular.reset_index(inplace = True)
others_sales = df['Global_Sales'].sum() - top10_popular['Global_Sales'].sum()
others_pop = {'Publisher':'others','Global_Sales':[others_sales]}
others_df_pop = pd.DataFrame(others_pop)
others_df_pop
top10_others_pop = pd.DataFrame(columns = ['Publisher','Global_Sales'],
index = ['0','1'])
top10_others_pop.iloc[0,0] = 'top10'
top10_others_pop.iloc[0,1] = top10_popular['Global_Sales'].sum()
top10_others_pop.iloc[1,:] = others_df_pop.iloc[0,:]
top10_others_pop
fig2 = plt.figure(figsize = (15,15))
ax3 = fig2.add_subplot(1,2,1)
plt.pie(top10_others_pop['Global_Sales'], labels = top10_others_pop['Publisher'], autopct = '%1.2ff%%')
plt.title('最受欢迎top10的发行商所占市场份额图')
ax4 = fig2.add_subplot(1,2,2)
plt.pie(top10_popular['Global_Sales'], labels = top10_popular['Publisher'], autopct = '%1.2ff%%')
plt.title('最受欢迎top10份额占比图')
top10_ = pd.merge(top10_popular, top10_publisher,how = 'outer')
top10_['Sales_Amount_Rate'] = top10_['Global_Sales'] / top10_['amount']
top10_
经过两表外连接后,不难看出:
- 游戏发行量top10与最受欢迎(销量高)发行商top10被相同十家巨头占据
- 由Sales_Amount_Rate指标可知,任天堂虽然发行游戏数在top10中较为中庸,在全球范围内仍是最受欢迎的游戏发行商
排名前10发行商发行游戏时间活跃度
publisher_time_active = df.pivot_table(index = ['Publisher', 'Year'],
values = 'Name',
aggfunc = {'Name':'count'}
)
publisher_time_active.rename(columns = {'Name':'Amount'}, inplace = True)
pta = publisher_time_active.reset_index()
pta
# 列出最具竞争力的十家发行商
tmp10 = top10_publisher['Publisher'].values
tmp10
frame1 = pta.loc[pta['Publisher'] == 'Electronic Arts', :]
frame1.set_index('Year', inplace = True)
frame2 = pta.loc[pta['Publisher'] == 'Activision', :]
frame2.set_index('Year', inplace = True)
frame3 = pta.loc[pta['Publisher'] == 'Namco Bandai Games', :]
frame3.set_index('Year', inplace = True)
frame4 = pta.loc[pta['Publisher'] == 'Ubisoft', :]
frame4.set_index('Year', inplace = True)
frame5 = pta.loc[pta['Publisher'] == 'Konami Digital Entertainment', :]
frame5.set_index('Year', inplace = True)
frame6 = pta.loc[pta['Publisher'] == 'THQ', :]
frame6.set_index('Year', inplace = True)
frame7 = pta.loc[pta['Publisher'] == 'Nintendo', :]
frame7.set_index('Year', inplace = True)
frame8 = pta.loc[pta['Publisher'] == 'Sony Computer Entertainment', :]
frame8.set_index('Year', inplace = True)
frame9 = pta.loc[pta['Publisher'] == 'Sega', :]
frame9.set_index('Year', inplace = True)
frame10 = pta.loc[pta['Publisher'] == 'Take-Two Interactive', :]
frame10.set_index('Year', inplace = True)
frame1.plot()
plt.title('Electronic Arts发行游戏时间活跃度')
plt.axis([1980,2021,0,121])
# plt.xticks(range(1980, 2021,5))
# plt.yticks(range(0, 121, 20))
frame2.plot()
plt.title('Activision发行游戏时间活跃度')
plt.xticks(range(1980, 2021,5))
plt.yticks(range(0, 121, 20))
frame3.plot()
plt.title('Namco Bandai Games发行游戏时间活跃度')
plt.xticks(range(1980, 2021,5))
plt.yticks(range(0, 121, 20))
frame4.plot()
plt.title('Ubisoft发行游戏时间活跃度')
plt.xticks(range(1980, 2021,5))
plt.yticks(range(0, 121, 20))
frame5.plot()
plt.title('Konami Digital Entertainment发行游戏时间活跃度')
plt.xticks(range(1980, 2021,5))
plt.yticks(range(0, 121, 20))
frame6.plot()
plt.title('THQ发行游戏时间活跃度')
plt.xticks(range(1980, 2021,5))
plt.yticks(range(0, 121, 20))
frame7.plot()
plt.title('Nintendo发行游戏时间活跃度')
plt.xticks(range(1980, 2021,5))
plt.yticks(range(0, 121, 20))
frame8.plot()
plt.title('Sony Computer Entertainment发行游戏时间活跃度')
plt.xticks(range(1980, 2021,5))
plt.yticks(range(0, 121, 20))
frame9.plot()
plt.title('Sega发行游戏时间活跃度')
plt.xticks(range(1980, 2021,5))
plt.yticks(range(0, 121, 20))
frame10.plot()
plt.title('Take-Two Interactive发行游戏时间活跃度')
plt.xticks(range(1980, 2021,5))
plt.yticks(range(0, 121, 20))
从上图可知,排名前十的游戏发行商都是从上世纪就开始发行游戏的老牌发行商
从上世纪九十年代末到2015年的二十年左右时间里大部分发行商发行游戏数量出现钟形走势,可能在这段时间里用户对电视游戏的需求也开始增长并逐渐趋于饱和
游戏角度
各类型游戏占比
genre_of_game = df.pivot_table(index = 'Genre',
values = ['Name', 'Global_Sales'],
aggfunc = {'Name':'count','Global_Sales':'sum'}
)
genre_of_game.rename(columns = {'Name':'Amount'}, inplace = True)
genre_of_game.sort_values(by = ['Global_Sales','Amount'], ascending = False)
genre_of_game.plot()
如图可知,游戏类型数量与受欢迎程度呈现一定正相关性
卖的最好的动作类游戏与运动类游戏同时也是游戏数量最多的两类
平台游戏的销售量与数量十分接近,可以看出发行的单位游戏数量的类型中平台游戏的销售量会是最高的
地区角度
各类型游戏于各地区受欢迎程度
genre_area = df.pivot_table(index = 'Genre',
values = ['NA_Sales','EU_Sales','JP_Sales','Other_Sales'],
aggfunc = {'NA_Sales':'sum',
'EU_Sales':'sum',
'JP_Sales':'sum',
'Other_Sales':'sum'
}
)
genre_area
genre_area.reset_index(inplace = True)
genre_area
add_up = {'Genre':'add_up',
'EU':[genre_area['EU_Sales'].sum()],
'JP':[genre_area['JP_Sales'].sum()],
'NA':[genre_area['NA_Sales'].sum()],
'Other':[genre_area['Other_Sales'].sum()]}
add_up_df = pd.DataFrame(add_up)
add_up_df
# 归一化
for i in range(0,len(genre_area.iloc[:,0])):
for j in range(1,len(genre_area.iloc[0,:])):
genre_area.iloc[i, j] = genre_area.iloc[i, j] / add_up_df.iloc[0, j]
genre_area
genre_area.set_index('Genre').T.plot.barh(figsize = (12,4), stacked = True)
- 欧洲区玩家最喜欢格斗、运动、射击类游戏,而对策略类游戏等兴趣较低,其他区域玩家与欧洲区偏好相仿
- 北美区玩家与欧洲区喜好相仿,由于欧美文化也经常会放在一起讨论,个人认为所以游戏也可以理解为与文化差异息息相关
- 日本区玩家对角色扮演游戏热爱程度最高,甚至拉出第二动作类游戏两倍之多,考虑到现实中日本的二次元、jk文化盛行,也许与此有关
平台角度
排名前10各平台游戏发行量 & 销售额(市场份额)
platform_df = df.pivot_table(index = 'Platform',
values = ['Name','Global_Sales'],
aggfunc = {'Name':'count','Global_Sales':'sum'})
platform_df.sort_values(by = ['Name','Global_Sales'], inplace = True, ascending = False)
platform_df
top10_platform = platform_df.iloc[:10,:]
top10_platform
排名前10的平台有任天堂的NDS、Wii、GBA,索尼的PS、PS2、PS3、PSP,微软的XB、X360和PC
由此可见主机游戏市场早已是三分天下
top10_platform.plot.bar()
plt.xticks(rotation = 45)
plt.title('排名前十各平台游戏发行量与销售额柱状图')
排名前10各平台中NDS和PS2的游戏发行数量遥遥领先,NDS、PS2、PS3、Wii、X360、PS这几个平台的市场份额并列最高,基本持平
时间角度
各年份游戏销量 & 各年份游戏发行量
year_sales = df.pivot_table(index = 'Year',
values = ['Global_Sales', 'Name'],
aggfunc = {'Global_Sales':'sum',
'Name':'count'})
year_sales
year_sales.plot(marker = '*')
plt.title('各年份游戏销量图')
由上图可知,从1980年代开始主机游戏销量震荡缓慢上涨,并在二十世纪初出现井喷式增长,最后在2010年左右剧烈下滑
初步分析与猜测:若不考虑数据源问题,2010年左右游戏市场趋于饱和,没有足够多有吸引力的新游戏上市,导致行业发展进入瓶颈期
每年各地区游戏销量
year_area_sales = df.pivot_table(index = 'Year',
values = ['EU_Sales','JP_Sales','NA_Sales'],
aggfunc = {'EU_Sales':'sum','JP_Sales':'sum','NA_Sales':'sum'})
year_area_sales
year_area_sales.plot(marker = '*')
plt.title('每年各地区的游戏销量折线图')
由上图可知,在主机游戏市场,北美区的销量基本上处于领先地位,日本区可能由于人口基数小的原因导致销量即使在2005-2010年的全球高速增长时期也表现一般
总结:
- 从各类指标top10中可知,动作类型的游戏普遍受众度更高
- 策略、解谜类型游戏的玩者较少
- 个人认为游戏属于第三产业,数据中表现的形式是经济发达地区与游戏的销量等关系有直接关系