In [1]:
from statistics import *
data = [1, 2, 2, 5, 10, 12]
print('{:0.2f}'.format(mean(data)))
In [3]:
from statistics import *
data = [1, 3, 3, 5, 10, 12]
print(mode(data))
In [4]:
from statistics import *
data = [1, 2, 2, 5, 10, 12]
print('median : {:0.2f}'.format(median(data)))
print('low : {:0.2f}'.format(median_low(data)))
print('high : {:0.2f}'.format(median_high(data)))
In [5]:
from statistics import *
import subprocess
def get_line_lengths():
cmd = 'wc -l ../[a-z]*/*.ipynb'
out = subprocess.check_output(
cmd, shell=True).decode('utf-8')
for line in out.splitlines():
parts = line.split()
if parts[1].strip().lower() == 'total':
break
nlines = int(parts[0].strip())
if not nlines:
continue # skip empty files
yield (nlines, parts[1].strip())
data = list(get_line_lengths())
lengths = [d[0] for d in data]
sample = lengths[::2]
print('Basic statistics:')
print(' count : {:3d}'.format(len(lengths)))
print(' min : {:6.2f}'.format(min(lengths)))
print(' max : {:6.2f}'.format(max(lengths)))
print(' mean : {:6.2f}'.format(mean(lengths)))
print('\nPopulation variance:')
print(' pstdev : {:6.2f}'.format(pstdev(lengths)))
print(' pvariance : {:6.2f}'.format(pvariance(lengths)))
print('\nEstimated variance for sample:')
print(' count : {:3d}'.format(len(sample)))
print(' stdev : {:6.2f}'.format(stdev(sample)))
print(' variance : {:6.2f}'.format(variance(sample)))
In [ ]: