моя проблема заключается в следующем, у меня есть этот фрейм данных, и я хотел бы сортировать groupby по неделям и годам. Например, конечный результат будет выглядеть примерно так: (я не делал вычисления для hour_duration для года nb 2018 и 2019)
Где мы всегда сохраняйте первые «start_date» для week_nb и year_nb, и мы суммируем все hour_duration
. Вы можете найти ниже частичного фрейма данных, потому что в полном наборе данных также есть week_nb = 2, 3 ... с соответствующий год
{'week_nb': {0: 1,
1: 1,
2: 1,
3: 1,
4: 1,
5: 1,
6: 1,
7: 1,
8: 1,
9: 1,
10: 1,
11: 1,
12: 1,
13: 1,
14: 1,
15: 1,
16: 1,
17: 1,
18: 1,
19: 1,
20: 1,
21: 1,
22: 1,
23: 1,
24: 1,
25: 1,
26: 1,
27: 1,
28: 2,
29: 2,
30: 2,
31: 2,
32: 2,
33: 2,
34: 2,
35: 2,
36: 2,
37: 2,
38: 2,
39: 2,
40: 2,
41: 2,
42: 2,
43: 2,
44: 2,
45: 2,
46: 2,
47: 2,
48: 2,
49: 2,
50: 2,
51: 2,
52: 2},
'year_nb': {0: 2017,
1: 2017,
2: 2017,
3: 2017,
4: 2017,
5: 2017,
6: 2017,
7: 2018,
8: 2018,
9: 2018,
10: 2018,
11: 2018,
12: 2018,
13: 2018,
14: 2019,
15: 2019,
16: 2019,
17: 2019,
18: 2019,
19: 2019,
20: 2019,
21: 2020,
22: 2020,
23: 2020,
24: 2020,
25: 2020,
26: 2020,
27: 2020,
28: 2017,
29: 2017,
30: 2017,
31: 2017,
32: 2017,
33: 2017,
34: 2017,
35: 2018,
36: 2018,
37: 2018,
38: 2018,
39: 2018,
40: 2018,
41: 2018,
42: 2019,
43: 2019,
44: 2019,
45: 2019,
46: 2019,
47: 2019,
48: 2019,
49: 2020,
50: 2020,
51: 2020,
52: 2020},
'start_date': {0: datetime.date(2017, 1, 2),
1: datetime.date(2017, 1, 3),
2: datetime.date(2017, 1, 4),
3: datetime.date(2017, 1, 5),
4: datetime.date(2017, 1, 6),
5: datetime.date(2017, 1, 7),
6: datetime.date(2017, 1, 8),
7: datetime.date(2018, 1, 1),
8: datetime.date(2018, 1, 2),
9: datetime.date(2018, 1, 3),
10: datetime.date(2018, 1, 4),
11: datetime.date(2018, 1, 5),
12: datetime.date(2018, 1, 6),
13: datetime.date(2018, 1, 7),
14: datetime.date(2018, 12, 31),
15: datetime.date(2019, 1, 1),
16: datetime.date(2019, 1, 2),
17: datetime.date(2019, 1, 3),
18: datetime.date(2019, 1, 4),
19: datetime.date(2019, 1, 5),
20: datetime.date(2019, 1, 6),
21: datetime.date(2019, 12, 30),
22: datetime.date(2019, 12, 31),
23: datetime.date(2020, 1, 1),
24: datetime.date(2020, 1, 2),
25: datetime.date(2020, 1, 3),
26: datetime.date(2020, 1, 4),
27: datetime.date(2020, 1, 5),
28: datetime.date(2017, 1, 9),
29: datetime.date(2017, 1, 10),
30: datetime.date(2017, 1, 11),
31: datetime.date(2017, 1, 12),
32: datetime.date(2017, 1, 13),
33: datetime.date(2017, 1, 14),
34: datetime.date(2017, 1, 15),
35: datetime.date(2018, 1, 8),
36: datetime.date(2018, 1, 9),
37: datetime.date(2018, 1, 10),
38: datetime.date(2018, 1, 11),
39: datetime.date(2018, 1, 12),
40: datetime.date(2018, 1, 13),
41: datetime.date(2018, 1, 14),
42: datetime.date(2019, 1, 7),
43: datetime.date(2019, 1, 8),
44: datetime.date(2019, 1, 9),
45: datetime.date(2019, 1, 10),
46: datetime.date(2019, 1, 11),
47: datetime.date(2019, 1, 12),
48: datetime.date(2019, 1, 13),
49: datetime.date(2020, 1, 6),
50: datetime.date(2020, 1, 7),
51: datetime.date(2020, 1, 8),
52: datetime.date(2020, 1, 9)},
'hour_duration': {0: 61.0,
1: 83.5,
2: 79.5,
3: 108.0,
4: 128.0,
5: 93.5,
6: 43.0,
7: 89.75,
8: 201.75,
9: 208.75,
10: 292.25,
11: 484.75,
12: 349.0,
13: 115.25,
14: 616.9166666666666,
15: 191.21666666666667,
16: 435.9166666666667,
17: 456.49999999999994,
18: 510.91666666666663,
19: 480.91666666666663,
20: 424.5,
21: 896.7500000000002,
22: 1315.0,
23: 595.1666666666667,
24: 902.0,
25: 1046.25,
26: 770.5,
27: 722.25,
28: 146.0,
29: 210.5,
30: 141.25,
31: 150.75,
32: 177.5,
33: 85.0,
34: 35.0,
35: 375.91666666666663,
36: 497.41666666666663,
37: 511.66666666666663,
38: 523.0,
39: 546.75,
40: 328.5,
41: 224.0,
42: 561.6666666666667,
43: 698.0833333333333,
44: 884.5,
45: 1109.0,
46: 1111.1666666666667,
47: 607.9166666666667,
48: 529.9166666666667,
49: 682.0,
50: 862.2069091666667,
51: 743.7139494444444,
52: 992.0}}