-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathranking.py
41 lines (26 loc) · 946 Bytes
/
ranking.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
import datetime
import pandas as pd
from utils import write_to_xls
df = pd.read_excel('./data.xlsx')
tr=0
d = dict()
finaldict = dict()
for colidx in range(len(df.columns)-1):
print('Processing for: ' + df.columns[colidx+1])
colname = df.columns[colidx+1]
for idx in range(len(df.get('Share'))):
# below line do only 1
if colidx == 0:
finaldict[df.get('Share')[idx]] = 0
d[df.get('Share')[idx]] = df.get(colname)[idx]
sorted_d = sorted(d.items(), key=lambda x:x[1], reverse=True)
# print(finaldict)
print(sorted_d)
for i in range(len(sorted_d)):
# print(f'{i+1} {sorted_d[i][0]}')
# add this score to finaldict
finaldict[sorted_d[i][0]] = finaldict[sorted_d[i][0]] + i+1
# print(finaldict)
finaldict = sorted(finaldict.items(), key=lambda x:x[1])
print(finaldict)
write_to_xls(finaldict, "ranking-"+ datetime.date.today().strftime('%Y-%b-%d'))