File tree Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Expand file tree Collapse file tree 1 file changed +46
-0
lines changed Original file line number Diff line number Diff line change
1
+ import pandas as pd
2
+ from collections import namedtuple , Counter
3
+
4
+
5
+ def convert_xls_into_dict (file_name ):
6
+
7
+ df = pd .read_excel (file_name , skip_blank_lines = False )
8
+
9
+ df = df .fillna ('None' )
10
+
11
+ uroks_dict = {urok [0 ]:[digit for digit in urok [1 :- 1 ] if type (digit ) == int or ',' in digit ]
12
+ for urok in df .values [2 :14 ]}
13
+
14
+ uroks_dict = {urok : align_scores_in_list (raw_scores_list ) for urok , raw_scores_list in uroks_dict .items ()}
15
+
16
+ return uroks_dict
17
+
18
+ def align_scores_in_list (raw_scores_list ):
19
+ aligned_list = []
20
+ for score in raw_scores_list :
21
+ if type (score ) == int :
22
+ aligned_list .append (score )
23
+ else :
24
+ aligned_list += [int (digit ) for digit in score .split (',' )]
25
+ return aligned_list
26
+
27
+ def average_score (list_of_scores ):
28
+ try :
29
+ return round (sum (list_of_scores )/ len (list_of_scores ), 1 )
30
+ except ZeroDivisionError :
31
+ print ('No scores!' )
32
+
33
+ def make_report (uroks ):
34
+ Urok = namedtuple ('Urok' , 'Name Scores Average_score' )
35
+ for k ,v in uroks .items ():
36
+ urok = Urok (Name = k , Scores = v , Average_score = average_score (v ))
37
+ print (urok .Name )
38
+ print (urok .Scores )
39
+ print (urok . Average_score )
40
+ print ('-' * 40 )
41
+
42
+ if __name__ == "__main__" :
43
+ file_name = "/home/python/Downloads/lessons.xls"
44
+ make_report (convert_xls_into_dict (file_name ))
45
+
46
+
You can’t perform that action at this time.
0 commit comments