【发布时间】:2017-09-08 09:51:00
【问题描述】:
我有这样的数据
ID 8-Jan 15-Jan 22-Jan 29-Jan 5-Feb 12-Feb LowerBound UpperBound
001 618 720 645 573 503 447 - -
002 62 80 67 94 81 65 - -
003 32 10 23 26 26 31 - -
004 22 13 1 28 19 25 - -
005 9 7 9 6 8 4 - -
我想使用 95% 置信区间为每个产品创建具有下限和上限的两列。我知道编写循环每个产品 ID 的函数的手动方式
import numpy as np
import scipy as sp
import scipy.stats
# Method copied from http://stackoverflow.com/questions/15033511/compute-a-confidence-interval-from-sample-data
def mean_confidence_interval(data, confidence=0.95):
a = 1.0*np.array(data)
n = len(a)
m, se = np.mean(a), scipy.stats.sem(a)
h = se * sp.stats.t._ppf((1+confidence)/2., n-1)
return m-h, m+h
Pandas 或(一种班轮的东西)有没有一种有效的方法?
【问题讨论】:
标签: python pandas numpy dataframe