gpt4 book ai didi

python - 新的 DataFrame 是每天的平均值

转载 作者:太空宇宙 更新时间:2023-11-03 14:22:46 27 4
gpt4 key购买 nike

    Site    Parameter   Date (LST)  Year    Month   Day Hour    Value   Unit    Duration    QC Name
1 Beijing PM2.5 2017-01-01 00:00:00 2017 1 1 0 505 µg/m_ 1 Hr Valid
2 Beijing PM2.5 2017-01-01 01:00:00 2017 1 1 1 485 µg/m_ 1 Hr Valid
3 Beijing PM2.5 2017-01-01 02:00:00 2017 1 1 2 466 µg/m_ 1 Hr Valid
4 Beijing PM2.5 2017-01-01 03:00:00 2017 1 1 3 435 µg/m_ 1 Hr Valid
5 Beijing PM2.5 2017-01-01 04:00:00 2017 1 1 4 405 µg/m_ 1 Hr Valid
6 Beijing PM2.5 2017-01-01 05:00:00 2017 1 1 5 402 µg/m_ 1 Hr Valid
7 Beijing PM2.5 2017-01-01 06:00:00 2017 1 1 6 407 µg/m_ 1 Hr Valid
8 Beijing PM2.5 2017-01-01 07:00:00 2017 1 1 7 435 µg/m_ 1 Hr Valid
9 Beijing PM2.5 2017-01-01 08:00:00 2017 1 1 8 472 µg/m_ 1 Hr Valid
10 Beijing PM2.5 2017-01-01 09:00:00 2017 1 1 9 465 µg/m_ 1 Hr Valid
11 Beijing PM2.5 2017-01-01 10:00:00 2017 1 1 10 473 µg/m_ 1 Hr Valid
12 Beijing PM2.5 2017-01-01 11:00:00 2017 1 1 11 456 µg/m_ 1 Hr Valid
13 Beijing PM2.5 2017-01-01 12:00:00 2017 1 1 12 474 µg/m_ 1 Hr Valid
14 Beijing PM2.5 2017-01-01 13:00:00 2017 1 1 13 510 µg/m_ 1 Hr Valid
15 Beijing PM2.5 2017-01-01 14:00:00 2017 1 1 14 596 µg/m_ 1 Hr Valid
16 Beijing PM2.5 2017-01-01 15:00:00 2017 1 1 15 580 µg/m_ 1 Hr Valid
17 Beijing PM2.5 2017-01-01 16:00:00 2017 1 1 16 556 µg/m_ 1 Hr Valid
18 Beijing PM2.5 2017-01-01 17:00:00 2017 1 1 17 522 µg/m_ 1 Hr Valid
19 Beijing PM2.5 2017-01-01 18:00:00 2017 1 1 18 495 µg/m_ 1 Hr Valid
20 Beijing PM2.5 2017-01-01 19:00:00 2017 1 1 19 500 µg/m_ 1 Hr Valid
21 Beijing PM2.5 2017-01-01 20:00:00 2017 1 1 20 484 µg/m_ 1 Hr Valid
22 Beijing PM2.5 2017-01-01 21:00:00 2017 1 1 21 452 µg/m_ 1 Hr Valid
23 Beijing PM2.5 2017-01-01 22:00:00 2017 1 1 22 427 µg/m_ 1 Hr Valid
24 Beijing PM2.5 2017-01-01 23:00:00 2017 1 1 23 444 µg/m_ 1 Hr Valid
25 Beijing PM2.5 2017-01-02 00:00:00 2017 1 2 0 428 µg/m_ 1 Hr Valid
26 Beijing PM2.5 2017-01-02 01:00:00 2017 1 2 1 466 µg/m_ 1 Hr Valid
27 Beijing PM2.5 2017-01-02 02:00:00 2017 1 2 2 452 µg/m_ 1 Hr Valid
28 Beijing PM2.5 2017-01-02 03:00:00 2017 1 2 3 442 µg/m_ 1 Hr Valid
29 Beijing PM2.5 2017-01-02 04:00:00 2017 1 2 4 390 µg/m_ 1 Hr Valid
30 Beijing PM2.5 2017-01-02 05:00:00 2017 1 2 5 317 µg/m_ 1 Hr Valid

如何从此处显示的(截断的)创建一个新的 DataFrame,该 DataFrame 显示了所有列,但不是显示逐小时的值,而是显示当天的平均值?

最佳答案

你可以尝试:

import datetime from datetime

df['Dates'] = df['Date (LST)'].dt.date

df['hour_average'] = df.groupby(['Dates'])['Hour'].transform('mean')

关于python - 新的 DataFrame 是每天的平均值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47835573/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com