code.Data
1import Cols 2import Row 3import Utils 4 5class Data: 6 def __init__(self, src): 7 self.cols = None 8 self.rows = [] 9 self.n = None 10 11 if type(src) == str: 12 Utils.parse_csv(src, self.add) 13 else: 14 for row in (src or []): 15 self.add(row) 16 17 def add(self, xs): 18 if not self.cols: 19 self.cols = Cols.Cols(xs) 20 else: 21 if hasattr(xs,'cells'): 22 self.rows.append(xs) 23 else: 24 row = Row.Row(xs) 25 self.rows.append(row) 26 for col in self.cols.x + self.cols.y: 27 col.add(row.cells[col.at]) 28 29 def stats(self, round_upto=2, showCols=None, fun=None): 30 showCols, fun = showCols or self.cols.y, fun or self.cols.mid 31 t = {} 32 for col in showCols: 33 v = fun(col) 34 if type(v) == float: 35 v = round(v, round_upto) 36 t[col.name] = v 37 return t
class
Data:
6class Data: 7 def __init__(self, src): 8 self.cols = None 9 self.rows = [] 10 self.n = None 11 12 if type(src) == str: 13 Utils.parse_csv(src, self.add) 14 else: 15 for row in (src or []): 16 self.add(row) 17 18 def add(self, xs): 19 if not self.cols: 20 self.cols = Cols.Cols(xs) 21 else: 22 if hasattr(xs,'cells'): 23 self.rows.append(xs) 24 else: 25 row = Row.Row(xs) 26 self.rows.append(row) 27 for col in self.cols.x + self.cols.y: 28 col.add(row.cells[col.at]) 29 30 def stats(self, round_upto=2, showCols=None, fun=None): 31 showCols, fun = showCols or self.cols.y, fun or self.cols.mid 32 t = {} 33 for col in showCols: 34 v = fun(col) 35 if type(v) == float: 36 v = round(v, round_upto) 37 t[col.name] = v 38 return t