-
Notifications
You must be signed in to change notification settings - Fork 0
/
analyze.py
42 lines (36 loc) · 974 Bytes
/
analyze.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
import pickle
import re
# import jieba
# import jieba.analyse
import operator
data = []
with open("./newsData.pkl", 'rb') as fr:
data = pickle.load(fr)
likes = dict()
posts = dict()
for i in range(len(data)):
authors = re.split('、|,' ,data[i][1].replace(" ",""))
likesCnt = data[i][2]
for author in authors:
try:
likes[author] += int(likesCnt)
posts[author] += 1
except:
likes[author] = int(likesCnt)
posts[author] = 1
authorAvgLikes = dict()
for author in likes:
authorAvgLikes[author] = int(likes[author]/posts[author])
print(sorted(authorAvgLikes.items(), key=operator.itemgetter(1)))
# allTag = []
# for i in range(1, len(data)):
# allTag += jieba.analyse.extract_tags(data[i][1],topK=3)
# d = {}
# for ele in allTag:
# try:
# d[ele] += 1
# except:
# d[ele] = 1
# d = sorted(d.items(), key=operator.itemgetter(1))
# for ele in d:
# print(ele[0])