我有一个文件“tancoyol.csv”,其中包含每 15 分钟记录的 Fecha、Temperatura、Humedad、PreciAcu 数据。它具有以下形式:
Fecha DirViento MagViento Temperatura HUmedad PreciAcu
2011-07-01 00:00:00 318 6.6 21.22 100 1.7
2011-07-01 00:15:00 342 5.5 21.20 100 1.7
2011-07-01 00:320:06 4.8
2011-07-01 00:45:00 279 7.5 21.11 100 4.2
2011-07-01 01:00:00 318 6.0 21.16 100 2.5
2011-07-01
01:15:00 329 7.4.1 21.13 1-10-20
01 01:30:00 300 4.7 21.15 100 1.3
2011-07-01 01:45:00 291 3.1 21.23 100 2.2
2011-07-01 02:00:00 284 7.6 21.29 100 1.3
2011-07-01 02:15:00 315 0.0 21.43 100
01-7 02:30:00 281 3.6 21.47 100 3.2
2011-07-01 02:45:00 0 2.7 21.52 100 2.5
2011-07-01 03:00:00 57 1.2 21.53 100 0.0
20151-07-01 03: 300 3.4 21.69 100 0.0
2011-07-01 03:30:00 359 5.9 21.67 100 0.0
2011-07-01 03:45:00 309 1.8 21.65 100 0.0
2011-07-01 04:00:00 244 13.4 21.64 100 0.0
2011-07-02 00:00:00 312 6.0 23.05 97 0.0
2011-07-02 00:15:00 318 6.3 22.79 100 02-3
02-3 00:30:00 303 9.1 22.44 100 0.7
2011-07-02 00:45:00 323 6.3 22.40 100 0.3
2011-07-02 01:00:00 319 5.4 22.07 100 0.7
2011-07-02: 4 3.9 21.89 100 0.8
2011-07-02 01:30:00 6 4.5 21.74 100 0.7
2011-07-02 01:45:00 310 5.0 21.72 100 1.3
2011-07-02 02:00:00 307 0.0 21.79 100 1.0
2011-07-02 02:15:00 5 3.4 21.78 100 1.2
2011-07-02
02:30:00 288 3.4 21.71-07 1.5 0-2
02:45:00 0 2.6 21.66 100 1.5
2011-07-02 03:00:00 280 5.8 21.48 100 1.3
2011-07-02 03:15:00 29 0.0 21.43 100 1.5
20101-07-02 03: 332 2.0 21.23 100 1.7
2011-07-02 03:45:00 148 0.0 21.06 100 1.5
2011-07-02 04:00:00 132 0.0 21.00 100 2.0
2011-07-03 00:00:00 308 8.0 21.93 99 0.3
2011-07-03
00:15:00 288 14.4 21.85 99 0.2
2011-07-03 00:30:00 354 3.1 21.85 99 03.3 20-
00:45:00 335 5.8 21.75 100 0.2
2011-07-03 01:00:00 274 2.7 21.68 100 0.0
2011-07-03 01:15:00 328 5.6 21.55 100 0.3
2011-07-03: 319 7.9 21.38 100 0.2
2011-07-03 01:45:00 322 5.1 21.32 100 0.3
2011-07-03 02:00:00 317 2.8 21.21 100 0.2
2011-07-03 02:15:00 322 5.3 21.08 100 0.3
2011-07-03
02:30:00 291 4.3 21.06 100 0.2
2011-07-03 02:45:00 284 5.7 21.014 100 0-3-7
03:00:00 310 2.7 21.05 100 0.2
2011-07-03 03:15:00 318 4.6 21.06 100 0.3
2011-07-03 03:30:00 299 7.4 21.05 100 0.2
2011-07-03: 238 0.0 20.99 100 0.3
2011-07-03 04:00:00 310 1.4 21.05 100 0.2
我要做的第一件事是获取 DirViento、MagViento、Temperatura 和 Humedad 列的平均值。我这样做如下:
import pandas as pd
import numpy as np
df = pd.read_csv('tancoyol.csv', parse_dates=[['Fecha','Hora']])
df1=df.set_index('Fecha_Hora')
prom_diario=df1.resample('D',how=np.mean)
print prom_diario
Fecha DirViento MagViento Temperatura Humedad PreciAcu
2011-07-01 318.000000 6.600000 21.220000 100.000000 1.700000
2011-07-02 273.470588 5.064706 21.474706 99.823529 1.688235
2011-07-03 200.705882 3.864706 21.775882 99.941176 1.076471
2011-07-04 306.812500 4.925000 21.310625 99.875000 0.231250
因为第 1 天、第 2 天和第 3 天的平均值没有完成,因为输出是滞后的,即第 2 天的平均值应该对应于第一天,依此类推。如何解决这个问题?现在,我不想获取 PreciAcu 列中的平均值,而是只获取 PreciAcu 列的每日总和,我该怎么做?最后,如何将输出(平均值和总和)存储到 csv 文件
我将非常感谢您的帮助