【发布时间】:2018-02-18 23:37:08
【问题描述】:
我正在使用 Python 中的 pandas 库。假设我通过以下方式从正态分布中抽取四个随机样本:
np.random.seed(12345)
df = pd.DataFrame([np.random.normal(32000,20000,3650),
np.random.normal(43000,10000,3650),
np.random.normal(43500,14000,3650),
np.random.normal(48000,7000,3650)],
index=[1992,1993,1994,1995])
我想得到每个样本的 95% 置信区间,因此我计算:
mean_value=df.mean(axis=1)
std_value=df.std(axis=1,ddof=0)
lower_bound=mean_value-1.96*std_value
upper_bound=mean_value+1.96*std_value
diff = upper_bound-lower_bound
对于每个置信区间,我想将其分成 11 个等间距的区间。我有一个类似的想法:
low=lower_bound.values[1]
high=upper_bound.values[1]
diff=0.09*diff.values[1]
np.arange(low,high,diff)
这不太奏效,因为切割区间不会在置信区间的上端结束。我怎样才能得到等距的间隔?
【问题讨论】:
-
我已编辑问题以消除重叠。
标签: python pandas numpy dataframe