/
utils.py
53 lines (44 loc) · 1.17 KB
/
utils.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
# -*- coding: utf-8 -*-
"""
Created on Thu Oct 24 16:58:33 2019
@author: DELL
"""
import collections
def readfile(file_name):
with open(file_name) as f:
#fo=f.read(fie_name) converts to raw string , dificut to processs
fo= f.readlines()
return fo
def getfield(data,line,position):
return data[line].split(':')[position].strip()
#def processtransaction(data,line,position):
def text_to_num(str):
return float(str)
def calc_mean(list1):
return sum(list1)/len(list1)
'''
def calc_count(list):
count=0
for i in list:
for j in list:
if (i == j):
count+=1
return count
'''
def calc_median(list1):
s= sorted(list1)
n=len(list1)
if (n/2==0):
n1=s[n//2-1]
n2=s[n//2+1]
return sum(n1,n2)/2
else:
return s[n//2]
def calc_mode(list1):
# max(set(list)),key=list.count()
data=collections.counter(list1)
datadic=dict(data)
max_value=max(datadic.values())
mode=[num for num,freq in datadic if freq==max_value]
return mode
#def calc_ess(list1):