-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest2.py
More file actions
53 lines (36 loc) · 1.13 KB
/
test2.py
File metadata and controls
53 lines (36 loc) · 1.13 KB
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
import pandas as pd
from collections import Counter
import sys
def get_popular_path(page):
df = pd.read_csv("records.csv")
# print(df['path'])
all_paths = []
# print(df)
for paths in df['path']:
if page in paths:
all_paths.append(str(paths.split(page)[0]+page))
all_paths1 = []
all_paths2 = []
for i in all_paths:
temp = i.split(" -> ")
all_paths1.append(temp[-4:])
for i in all_paths1:
temp = " -> ".join(i)
all_paths2.append(temp)
max_key_val = find_max_frequency(all_paths2)
return max_key_val
def find_max_frequency(my_list):
freq = {}
for item in my_list:
if (item in freq):
freq[item] += 1
else:
freq[item] = 1
# for key, value in freq.items():
# print ("% s : % d"%(key, value))
max_key_val = max(zip(freq.values(), freq.keys()))
return list(max_key_val)
if __name__=='__main__':
page = sys.argv[1]
path = get_popular_path(page)
print("Popular Page is "+path[1]+" with "+str(path[0])+" hits")