Pandas:计算每小时数据的列平均值

2024-05-23 17:00:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我有一个像这样的数据帧('Timestamp'在datetime type和索引列中):

                                    Server Citta Nazione  download Mb/s  upload Mb/s     ping            Isp
Timestamp                                                                                                   
2020-04-01 11:02:04        AlternatYva srl  Rome   Italy      12.550000     0.890000   70.918  Warian S.R.L.
2020-04-01 11:04:12        AlternatYva srl  Rome   Italy      10.880000     0.510000   64.908  Warian S.R.L.
2020-04-01 11:06:07            Fastweb SpA  Rome   Italy      11.200000     0.650000   63.223  Warian S.R.L.
2020-03-23 05:00:13            Fastweb SpA  Rome   Italy      13.956026     0.629037   31.809  Warian S.R.L.
2020-03-23 05:02:08        AlternatYva srl  Rome   Italy      10.887535     0.224637   31.200  Warian S.R.L.
...                                    ...   ...     ...            ...          ...      ...            ...
2020-04-07 09:03:37        AlternatYva srl  Rome   Italy      12.560000     1.030000   55.119  Warian S.R.L.
2020-04-07 09:05:12            Fastweb SpA  Rome   Italy      13.640000     0.770000   29.715  Warian S.R.L.
2020-04-25 02:01:52        AlternatYva srl  Rome   Italy      10.990000     0.040000   74.318  Warian S.R.L.
2020-04-25 02:03:28  Telecom Italia S.p.A.  Rome   Italy      11.510000     1.090000  137.830  Warian S.R.L.
2020-04-25 02:04:56  Telecom Italia S.p.A.  Rome   Italy      12.960000     0.330000   65.324  Warian S.R.L.

[6726 rows x 7 columns]

我想用“下载Mb/s”列每小时的下载平均值创建一个新的df。两列小时-平均值。比如:

HOUR   mean
0       12.
1       13.5
2        4.8
3        9.6
...
23      10.2

到目前为止,我能够通过mean()函数计算主数据帧的“download Mb/s”列的值。我知道,使用between_time()函数,我可以选择索引列“Timestamp”的小时之间的所有行

将这两个函数聚合在一起以获得如上所述的数据帧的正确方法是什么


Tags: 数据函数downloadmbtimestamp小时spaitalia