简体   繁体   English

均值由数组的间隔,Python中的标准差(Pandas)

[英]Mean by interval of an array, standard deviation in python (Pandas)

I'd like to calculate the mean and the standar deviation of many consecutive intervals of two related arrays (List below), where the first two columns are (let's say) time and distance respectively. 我想计算两个相关数组的许多连续间隔的平均值和标准偏差(下面的列表),其中前两列分别是(假设)时间和距离。 The third, fourth and fifth are mean time (central), mean distance and the deviation standard. 第三,第四和第五是平均时间(中心),平均距离和偏差标准。 (Actually i made this list by hand). (实际上我是手工制作的)。 How you can see in the example the mean and standard deviation are made for each three consecutive intervals (But in general can be over 4 by 4, 10 by 10 and so on). 在示例中,您如何看到均值和标准差是针对每个连续三个时间间隔进行的(但通常可以超过4×4、10×10,依此类推)。

So, I've got similar long lists and i wanna calculate (maybe with PANDAS, NUMPY and/or SCIPY) something like this doing some loop and create they arrays of mean time, mean distance and deviation standar. 因此,我有类似的长列表,我想计算(也许使用PANDAS,NUMPY和/或SCIPY)这样的循环,并创建它们的平均时间,平均距离和标准偏差数组。 Therefore be able to plot distance versus time and plot the mean values for time and distance with its standard deviation (error, known as sigma) 因此,能够绘制距离与时间的关系,并绘制时间和距离的平均值及其标准偏差(误差,称为sigma)

1  1   2  4.6   3.29
2  4   5  25.6  8.17
3  9   8  64.6  13.07
4  16  11 121.6 17.96
5  25  14 196.6 22.86
6  36  17 289.6 27.76
7  49  20 400.6 32.66
8  64
9  81
10 100
11 121
12 144
13 169
14 196
15 225
16 256
17 289
18 324
19 361
20 400
21 441

i plotted this using errorbar , but my problem is how to do the loop for each interval 我使用errorbar绘制了这个,但是我的问题是如何在每个间隔内执行循环

在此处输入图片说明

You can do this with numpy . 您可以使用numpy做到这一点。 reshape can be used to group data into chunks to calculate stats: reshape可用于将数据分组为块以计算统计信息:

import numpy as np

// data
time = np.arange(1.0,22.0)
distance = time ** 2

// group data into chunks to get stats
meanTime = np.mean(time.reshape(-1,3),axis=1)
meanDistance = np.mean(distance.reshape(-1,3), axis=1)
std = np.std(distance.reshape(-1,3), axis=1)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM