Python statistics 模块,pvariance() 实例源码
我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用statistics.pvariance()。
def PVARIANCE(df, n, price='Close', mu=None):
"""
Population variance of data
"""
pvariance_list = []
i = 0
while i < len(df[price]):
if i + 1 < n:
pvariance = float('NaN')
else:
start = i + 1 - n
end = i + 1
pvariance = statistics.pvariance(df[price][start:end], mu)
pvariance_list.append(pvariance)
i += 1
return pvariance_list
def pvariance(self):
return statistics.pvariance(self.price)
# ??
def main():
print(stats.mean(range(6)))
print(stats.median(range(6)))
print(stats.median_low(range(6)))
print(stats.median_high(range(6)))
print(stats.median_grouped(range(6)))
try:
print(stats.mode(range(6)))
except Exception as e:
print(e)
print(stats.mode(list(range(6)) + [3]))
print(stats.pstdev(list(range(6)) + [3]))
print(stats.stdev(list(range(6)) + [3]))
print(stats.pvariance(list(range(6)) + [3]))
print(stats.variance(list(range(6)) + [3]))
def test_compare_to_variance(self):
# Test that stdev is,in fact,the square root of variance.
data = [random.uniform(-17, 24) for _ in range(1000)]
expected = math.sqrt(statistics.pvariance(data))
self.assertEqual(self.func(data), expected)
def test_compare_to_variance(self):
# Test that stdev is, expected)
def pvariance(text):
"""
Finds the population variance of a space-separated list of numbers.
Example::
/pvariance 33 54 43 65 43 62
"""
return format_output(statistics.pvariance(parse_numeric_list(text)))