-
Notifications
You must be signed in to change notification settings - Fork 1
/
Game_Streamer_Analysis.py
184 lines (115 loc) · 5.56 KB
/
Game_Streamer_Analysis.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#!/usr/bin/env python
# coding: utf-8
# ### Project : Game Streamer Analysis
# ### Author : Sanjoy Kumar
# ### Email : [email protected]
# ### Portfolio : imsanjoykb.github.io
# ## Import Necessary Libraries
import pandas as pd
import numpy as np
import matplotlib.pylab as plt
import datetime
import missingno as msno
from collections import Counter
# ## Import Data Source
data_source = 'Maingames_DS_dataset.csv'
df = pd.read_csv(data_source, index_col="Unnamed: 0")
df.head(5)
# ## Data Internal Insights
df.shape
df.isnull().sum()
df.describe()
# ## Data Cleaning
# Drop NA value (value = '-')
df = df[df.Game != '-']
df = df[df.Game != 'No MLBB Video']
# Merge same game name
# Arena of Valor
df['Game'] = df['Game'].replace(['Garena Liên Quân Mobile','Liên Quân Mobile'],'Arena of Valor')
# Age of Empires
df['Game'] = df['Game'].replace(['Agge of Empires'],'Age of Empires')
# Audition online
df['Game'] = df['Game'].replace(['Audition'],'Audition Online')
df['Game'] = df['Game'].replace(['Call of Duty: Mobile VN'],'Call of Duty: Mobile')
df['Total Follower'] = df['Total Follower'].replace(['250,98'],25098)
# change datatype
df['Total Follower'] = pd.to_numeric(df['Total Follower'])
# Other
df['PaidStarPerWatchedHourPerFollower'] = df['PaidStarPerWatchedHour']/df['Total Follower']
# Show all games
for game in df.groupby('Game').groups.keys():
print(game)
df.groupby('Game').groups.keys()
df.groupby('Game').count().iloc[:,0].shape
# Generate game count
df_game_count = df.groupby('Game').count().sort_values('Country', ascending=False).iloc[:, 0:1].rename(columns={'Country':'Count'})
# df_game_count.head(10)
# ## Check Per Followers
cols = ['Total Follower','PaidStarPerWatchedHour'] # The columns you want to search for outliers in
# Calculate quantiles and IQR
Q1 = df[cols].quantile(0.25) # Same as np.percentile but maps (0,1) and not (0,100)
Q3 = df[cols].quantile(0.75)
IQR = Q3 - Q1
# Return a boolean array of the rows with (any) non-outlier column values
condition = ~((df[cols] < (Q1 - 1.5 * IQR)) | (df[cols] > (Q3 + 1.5 * IQR))).any(axis=1)
# Filter our dataframe based on condition
filtered_df = df[condition]
filtered_df.shape
filtered_df[['Total Follower', 'PaidStarPerWatchedHourPerFollower']].plot(x='Total Follower', y='PaidStarPerWatchedHourPerFollower', grid=True, kind='scatter')
# select data of PaidStarPerWatchedHourPerFollower in Q3-Q4
cols = ['PaidStarPerWatchedHourPerFollower']
Q1 = df[cols].quantile(0.25)
Q3 = df[cols].quantile(0.75)
condition = (df[cols]>Q3).any(axis=1)
df_filtered_by_PSPWPF = df[condition]
c = df_filtered_by_PSPWPF.corr()
c['PSPW_abs'] = c['PaidStarPerWatchedHour'].apply(lambda x: abs(x))
c_rank = c[['PaidStarPerWatchedHour', 'PSPW_abs']].sort_values('PSPW_abs', ascending=False)[c['PSPW_abs'] > c['PSPW_abs'].mean()]
c_rank = c_rank.iloc[3:]
c_rank.head(10)
# ## Correlation Matrix with General Data
corr_matrix = df.corr()
corr_matrix['PSPW_abs'] = corr_matrix['PaidStarPerWatchedHour'].apply(lambda x: abs(x))
corr_core = corr_matrix[['PaidStarPerWatchedHour', 'PSPW_abs']]
corr_core.sort_values('PSPW_abs', ascending=False).head(10)
# ## Divide into several group: Country, Game, Genger
# Distribution of VN, PUBG, Male
vpm = df.loc[df['Game'] == 'PUBG'].loc[df['Country'] == 'VN'].loc[df['Gender'] == 'Male']
test_corr = vpm.corr()
test_corr['PSPW_abs'] = test_corr['PaidStarPerWatchedHour'].apply(lambda x: abs(x))
test_corr = test_corr[['PaidStarPerWatchedHour', 'PSPW_abs']]
test_corr
# select data of PaidStarPerWatchedHourPerFollower in Q3-Q4
cols = ['PSPW_abs']
Q3 = test_corr[cols].quantile(0.75)
condition = (test_corr[cols]>Q3).any(axis=1)
test_corr = test_corr[condition]
test_corr = test_corr.sort_values('PSPW_abs',ascending= False).iloc[3:,1:]
test_corr
test_corr.head(5).plot(kind='barh')
# Distribution of VN, PUBG, Female
vpf = df.loc[df['Game'] == 'PUBG'].loc[df['Country'] == 'VN'].loc[df['Gender'] == 'Female']
test_corr_f = vpf.corr()
test_corr_f['PSPW_abs'] = test_corr_f['PaidStarPerWatchedHour'].apply(lambda x: abs(x))
test_corr_f = test_corr_f[['PaidStarPerWatchedHour', 'PSPW_abs']]
test_corr_f
# select data of PaidStarPerWatchedHourPerFollower in Q3-Q4
cols = ['PSPW_abs']
Q3 = test_corr_f[cols].quantile(0.75)
condition = (test_corr_f[cols]>Q3).any(axis=1)
test_corr_f = test_corr_f[condition]
test_corr_f = test_corr_f.sort_values('PSPW_abs',ascending= False)[test_corr_f['PSPW_abs'] > test_corr_f['PSPW_abs'].mean()].iloc[3:,1:]
test_corr_f.plot(kind='barh')
# print(df.groupby('Country').mean()['PaidStarPerWatchedHour'])
print(df.groupby('Country').mean()['PaidStarPerWatchedHour']/df.groupby('Country').count()['PaidStarPerWatchedHour'])
(df.groupby('Country').mean()['PaidStarPerWatchedHour']/df.groupby('Country').count()['PaidStarPerWatchedHour']).plot(kind='barh')
df[df['Gender'] == 'Male'].groupby('Country').mean()['PaidStarPerWatchedHour'].plot(kind='barh')
df[df['Gender'] == 'Female'].groupby('Country').mean()['PaidStarPerWatchedHour'].plot(kind='barh')
df.groupby('Gender').mean()['PaidStarPerWatchedHour'].plot(kind='barh')
df[df['Country'] == 'PH'].groupby('Gender').mean()['PaidStarPerWatchedHour'].plot(kind='barh')
print(df.groupby('Gender').mean()['PaidStarPerWatchedHour']/df.groupby('Gender').count()['PaidStarPerWatchedHour'])
(df.groupby('Gender').mean()['PaidStarPerWatchedHour']/df.groupby('Gender').count()['PaidStarPerWatchedHour']).plot(kind='barh')
df[df['Country'] == 'VN'].groupby('Gender').mean()['PaidStarPerWatchedHour'].plot(kind='barh')
df[df['Country'] == 'ID'].groupby('Gender').mean()['PaidStarPerWatchedHour'].plot(kind='barh')
# ## Thank you
# In[ ]: