天的均值

时间:2018-11-21 09:04:51

标签: python-3.x time pandas-groupby

我有以下数据集

                   dVal              eVal
0        2015-01-01 00:00:00.000  3.622833
1        2015-01-01 01:00:00.000  3.501333
2        2015-01-01 02:00:00.000  3.469167
3        2015-01-01 03:00:00.000  3.436333
4        2015-01-01 04:00:00.000  3.428000
5        2015-01-01 05:00:00.000  3.400667
6        2015-01-01 06:00:00.000  3.405667
7        2015-01-01 07:00:00.000  3.401500
8        2015-01-01 08:00:00.000  3.404333
9        2015-01-01 09:00:00.000  3.424833
10       2015-01-01 10:00:00.000  3.489500
11       2015-01-01 11:00:00.000  3.521000
12       2015-01-01 12:00:00.000  3.527833
13       2015-01-01 13:00:00.000  3.523500
14       2015-01-01 14:00:00.000  3.511667
15       2015-01-01 15:00:00.000  3.602500
16       2015-01-01 16:00:00.000  3.657667
17       2015-01-01 17:00:00.000  3.616667
18       2015-01-01 18:00:00.000  3.534500
19       2015-01-01 19:00:00.000  3.529167
20       2015-01-01 20:00:00.000  3.548167
21       2015-01-01 21:00:00.000  3.565500
22       2015-01-01 22:00:00.000  3.539833
23       2015-01-01 23:00:00.000  3.485667
24       2015-01-02 00:00:00.000  3.493167
.........
.........

我想按天计算eVal列的平均值。 第一步是将dVal列转换为datetime。

time['dVal'] = pd.to_datetime(time['dVal'])

接下来,我将datetime列设置为索引

time.index = time['dVal']

最后,我算出每天的平均值

me = time.resample('D').mean()

计算得出的均值是错误的。

dVal         eVal
2015-01-01  4.014973  --> The correct mean of the first day is 3.5
2015-01-02  4.006548
2015-01-03  4.010406
2015-01-04  4.034531

0 个答案:

没有答案