From ac2ae9322ea7db874f9d729a50f995212c42852e Mon Sep 17 00:00:00 2001 From: Marco Biasini <mvbiasini@gmail.com> Date: Mon, 13 Aug 2012 07:52:32 +0200 Subject: [PATCH] added convenience function to summarize column --- modules/base/pymod/table.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/modules/base/pymod/table.py b/modules/base/pymod/table.py index 40fc98b46..cb505d3ae 100644 --- a/modules/base/pymod/table.py +++ b/modules/base/pymod/table.py @@ -415,6 +415,31 @@ class Table(object): def __str__(self): return self.ToString() + def Stats(self, col): + idx = self.GetColIndex(col) + text =''' +Statistics for column %(col)s + + Number of Rows : %(num)d + Number of Rows Not None: %(num_non_null)d + Mean : %(mean)f + Median : %(median)f + Standard Deviation : %(stddev)f + Min : %(min)f + Max : %(max)f +''' + data = { + 'col' : col, + 'num' : len(self.rows), + 'num_non_null' : self.Count(col), + 'median' : self.Median(col), + 'mean' : self.Mean(col), + 'stddev' : self.StdDev(col), + 'min' : self.Min(col), + 'max' : self.Max(col), + } + return text % data + def _AddRowsFromDict(self, d, overwrite=None): ''' Add one or more rows from a :class:`dictionary <dict>`. -- GitLab