-
Notifications
You must be signed in to change notification settings - Fork 0
/
Graphical_Analysis_emacs.py
365 lines (296 loc) · 11.6 KB
/
Graphical_Analysis_emacs.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
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
from google.colab import drive # This is used to connect with the google drive to save the generated datasets
import pandas as pd #used for importing, creating, saving, and manipulating datasets
import seaborn as sns #used for ploting graphs
import matplotlib.pyplot as plt #used for plotting graphs
from statistics import mean #for calculating average
drive.mount('/gdrive/') #mounting google-drive
#importing dataset with the posts from r/emacs
emacs_df=pd.read_csv('/gdrive/My Drive/DrAdams_Task3_Files/CSV/emacs_finalDF.csv')
emacs_df
#Finding the correlation with an heatmap
cor_emacs = emacs_df.corr()
plot_t=sns.heatmap(cor_emacs)
figure = plot_t.get_figure()
figure.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/Heatmap_emacs.png')
#declaring the months
months = ['Jan', 'Feb', 'Mar']
#r/emacs: Monthwise upvote Bar plot
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #adding the axes
emacs_UpvoteMonthWise=[]
#iterating over months
for i in months:
month_temporary = emacs_df[emacs_df['month']==i]
emacs_UpvoteMonthWise.append(month_temporary['upvote count'].sum()) #Calculating the sum of the upvote count for each month
ax.bar(months,emacs_UpvoteMonthWise,color='r')
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/UpvoteF_monthwiseBar.png') #saving the plot
plt.show()
#r/emacs: UpVote Frequency change in January
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #adding the axes
upvtAvg_emacs_jan=[]
day=[]
janEmacs_upvote = emacs_df[emacs_df['month']=='Jan']
#iterating over days in Jan
for i in range(1,32):
janemacsTemp=janEmacs_upvote[janEmacs_upvote['day']==i]
janemacsTemp.reset_index(drop=True,inplace=True)
upvt_day=[]
for j in range(len(janemacsTemp)):
upvt_day.append(janemacsTemp['upvote count'][j])
upvtAvg_emacs_jan.append(mean(upvt_day)) #Calculating the average frequency each day
day.append(i)
ax.plot(day,upvtAvg_emacs_jan, '-.r')
ax.set_xlabel('Day in Jan')
ax.set_ylabel('Upvote Frequency')
plt.legend(['January'])
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/UpvoteFreq_daywise_jan.png') #saving the image
plt.show()
#r/emacs: UpVote Frequency change in February
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #adding the axes
upvtAvg_emacs_feb=[]
day_feb=[]
febEmacs_upvote = emacs_df[emacs_df['month']=='Feb']
#Iterating over the days in Feb
for i in range(1,30):
febemacsTemp=febEmacs_upvote[febEmacs_upvote['day']==i]
febemacsTemp.reset_index(drop=True,inplace=True)
upvt_day=[]
for j in range(len(febemacsTemp)):
upvt_day.append(febemacsTemp['upvote count'][j])
upvtAvg_emacs_feb.append(mean(upvt_day)) #Calculating the average frequency each day
day_feb.append(i)
#plotting
ax.plot(day_feb,upvtAvg_emacs_feb, '-.r')
ax.set_xlabel('Day in Feb')
ax.set_ylabel('Upvote Frequency')
plt.legend(['February'])
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/UpvoteFreq_daywise_feb.png') #saving the image
plt.show()
#r/emacs: UpVote Frequency change in March
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #adding the axes
upvtAvg_emacs_mar=[]
day=[]
marEmacs_upvote = emacs_df[emacs_df['month']=='Mar']
#iterating over the days in March
for i in range(1,32):
maremacsTemp=marEmacs_upvote[marEmacs_upvote['day']==i]
maremacsTemp.reset_index(drop=True,inplace=True)
upvt_day=[]
for j in range(len(maremacsTemp)):
upvt_day.append(maremacsTemp['upvote count'][j])
upvtAvg_emacs_mar.append(mean(upvt_day)) #Calculating the average frequency each day
day.append(i)
#plotting
ax.plot(day,upvtAvg_emacs_mar, '-.r')
ax.set_xlabel('Day in Mar')
ax.set_ylabel('Upvote Frequency')
plt.legend(['March'])
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/UpvoteFreq_daywise_mar.png') #saving the image
plt.show()
#r/emacs: UpVote Frequency change of all months together
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #adding the axes
ax.plot(day,upvtAvg_emacs_jan, '-.r')
ax.plot(day_feb,upvtAvg_emacs_feb, '-.g')
ax.plot(day,upvtAvg_emacs_mar, '-.b')
ax.set_xlabel('Day')
ax.set_ylabel('Upvote Frequency')
plt.legend(['January','February','March'])
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/UpvoteFreq_daywise_3months.png') #saving the image
plt.show()
#r/emacs: UpVote ratio change in January
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #adding the axes
upvtRAvg_emacs_jan=[]
day=[]
janEmacs_upvoteR = emacs_df[emacs_df['month']=='Jan']
#iterating over the days in Jan
for i in range(1,32):
janemacsTemp=janEmacs_upvoteR[janEmacs_upvoteR['day']==i]
janemacsTemp.reset_index(drop=True,inplace=True)
upvtR_day=[]
for j in range(len(janemacsTemp)):
upvtR_day.append(janemacsTemp['upvote ratio'][j])
upvtRAvg_emacs_jan.append(mean(upvtR_day)) #calculating the mean upvote ratio
day.append(i)
ax.plot(day,upvtRAvg_emacs_jan, '-.b')
ax.set_xlabel('Day in Jan')
ax.set_ylabel('Upvote Ratio')
plt.legend(['January'])
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/UpvoteRatio_daywise_jan.png') #saving the image
plt.show()
#r/emacs: UpVote ratio change in February
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #adding the axes
upvtRAvg_emacs_feb=[]
day_feb=[]
febEmacs_upvoteR = emacs_df[emacs_df['month']=='Feb']
#iterating over the days in feb
for i in range(1,30):
febemacsTemp=febEmacs_upvoteR[febEmacs_upvoteR['day']==i]
febemacsTemp.reset_index(drop=True,inplace=True)
upvtR_day=[]
for j in range(len(febemacsTemp)):
upvtR_day.append(febemacsTemp['upvote ratio'][j])
upvtRAvg_emacs_feb.append(mean(upvtR_day)) #calculating the mean upvote ratio
day_feb.append(i)
ax.plot(day_feb,upvtRAvg_emacs_feb, '-.b')
ax.set_xlabel('Day in Feb')
ax.set_ylabel('Upvote Ratio')
plt.legend(['February'])
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/UpvoteRatio_daywise_feb.png') #saving the image
plt.show()
#r/emacs: UpVote ratio change in March
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #adding the axes
upvtRAvg_emacs_mar=[]
day=[]
marEmacs_upvoteR = emacs_df[emacs_df['month']=='Mar']
#Iterating over the days in Mar
for i in range(1,32):
maremacsTemp=marEmacs_upvoteR[marEmacs_upvoteR['day']==i]
maremacsTemp.reset_index(drop=True,inplace=True)
upvtR_day=[]
for j in range(len(maremacsTemp)):
upvtR_day.append(maremacsTemp['upvote ratio'][j])
upvtRAvg_emacs_mar.append(mean(upvtR_day)) #calculating the mean upvote ratio
day.append(i)
ax.plot(day,upvtRAvg_emacs_mar, '-.b')
ax.set_xlabel('Day in Mar')
ax.set_ylabel('Upvote Ratio')
plt.legend(['March'])
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/UpvoteRatio_daywise_mar.png')
plt.show()
#r/emacs: UpVote ratio change of all months together
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #adding the axes
ax.plot(day,upvtRAvg_emacs_jan, '-.r')
ax.plot(day_feb,upvtRAvg_emacs_feb, '-.g')
ax.plot(day,upvtRAvg_emacs_mar, '-.b')
ax.set_xlabel('Day')
ax.set_ylabel('Upvote Ratio')
plt.legend(['January','February','March'])
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/UpvoteRatioChange_daywise_3months.png') #saving the image
plt.show()
#r/emacs: Comments Frequency monthwise
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #adding the axes
emacs_commentMonthWise=[]
#Iterating over the months
for i in months:
month_temporary = emacs_df[emacs_df['month']==i]
emacs_commentMonthWise.append(month_temporary['comments count'].sum())
ax.bar(months,emacs_commentMonthWise, color='b')
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/commentFreq_monthwiseBar.png') #saving the image
plt.show()
#r/emacs: Comments Frequency change in January
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #adding the axes
cmmtAvg_emacs_jan=[]
day=[]
janEmacs_comment = emacs_df[emacs_df['month']=='Jan']
#Iterating over the days in Jan
for i in range(1,32):
janemacsTemp=janEmacs_comment[janEmacs_comment['day']==i]
janemacsTemp.reset_index(drop=True,inplace=True)
cmmt_day=[]
for j in range(len(janemacsTemp)):
cmmt_day.append(janemacsTemp['comments count'][j])
cmmtAvg_emacs_jan.append(mean(cmmt_day)) #taking the average comment counts per day
day.append(i)
ax.plot(day,cmmtAvg_emacs_jan, '-.g')
ax.set_xlabel('Day in Jan')
ax.set_ylabel('Comments')
plt.legend(['January'])
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/commentFreq_jan.png') #saving the image
plt.show()
#r/emacs: Comments Frequency change in February
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #adding the axes
cmmtAvg_emacs_feb=[]
day_feb=[]
febEmacs_comment = emacs_df[emacs_df['month']=='Feb']
#iterating over the days in feb
for i in range(1,30):
febemacsTemp=febEmacs_comment[febEmacs_comment['day']==i]
febemacsTemp.reset_index(drop=True,inplace=True)
cmmt_day=[]
for j in range(len(febemacsTemp)):
cmmt_day.append(febemacsTemp['comments count'][j])
cmmtAvg_emacs_feb.append(mean(cmmt_day)) #taking the average comment counts each day
day_feb.append(i)
ax.plot(day_feb,cmmtAvg_emacs_feb, '-.g')
ax.set_xlabel('Day in February')
ax.set_ylabel('Comments')
plt.legend(['February'])
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/commentFreq_feb.png') #saving the image
plt.show()
#r/emacs: Comments Frequency change in March
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #adding the axes
cmmtAvg_emacs_mar=[]
day=[]
marEmacs_comment = emacs_df[emacs_df['month']=='Mar']
#iterating over the days in March
for i in range(1,32):
maremacsTemp=marEmacs_comment[marEmacs_comment['day']==i]
maremacsTemp.reset_index(drop=True,inplace=True)
cmmt_day=[]
for j in range(len(maremacsTemp)):
cmmt_day.append(maremacsTemp['comments count'][j])
cmmtAvg_emacs_mar.append(mean(cmmt_day)) #taking the average comment counts each day
day.append(i)
ax.plot(day,cmmtAvg_emacs_mar, '-.g')
ax.set_xlabel('Day in March')
ax.set_ylabel('Comments')
plt.legend(['March'])
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/commentFreq_mar.png') #saving the image
plt.show()
#r/emacs: Comments Frequency change of all months together
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #adding the axes
ax.plot(day,cmmtAvg_emacs_jan, '-.r')
ax.plot(day_feb,cmmtAvg_emacs_feb, '-.g')
ax.plot(day,cmmtAvg_emacs_mar, '-.b')
ax.set_xlabel('Day')
ax.set_ylabel('Comments')
plt.legend(["March","February","January"])
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/commentFreq_daywise_3months.png') #saving the image
plt.show()
#r/emacs: Comments and upvote Frequency analysis together in Jan
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #aadding the axes
ax.plot(day,upvtAvg_emacs_jan, '-.r')
ax.plot(day,cmmtAvg_emacs_jan, '-.g')
ax.set_xlabel('Day')
ax.set_ylabel('Count')
plt.legend(['Upvote','Comments'])
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/commentUpvote_daywise_Jan.png') #saving the image
plt.show()
#r/emacs: Comments and upvote Frequency analysis together in Feb
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #adding the axes
ax.plot(day_feb,upvtAvg_emacs_feb, '-.r')
ax.plot(day_feb,cmmtAvg_emacs_feb, '-.g')
ax.set_xlabel('Day')
ax.set_ylabel('Count')
plt.legend(['Upvote','Comments'])
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/commentUpvote_daywise_Feb.png') #saving the image
plt.show()
#r/emacs: Comments and upvote Frequency analysis together in March
fig = plt.figure()
ax = fig.add_axes([0,0,1,1]) #adding the axes
ax.plot(day,upvtAvg_emacs_mar, '-.r')
ax.plot(day,cmmtAvg_emacs_mar, '-.g')
ax.set_xlabel('Day')
ax.set_ylabel('Count')
plt.legend(['Upvote','Comments'])
plt.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/commentUpvote_daywise_Mar.png') #saving the image
plt.show()
#r/emacs: Number of Posts monthwise
plot_t = sns.countplot(x='month', data=emacs_df)
figure = plot_t.get_figure()
figure.savefig('/gdrive/My Drive/DrAdams_Task3_Files/PNG/r_emacs/PostFreq_monthwise.png') #saving the image