回答編集履歴
2
修正
answer
CHANGED
@@ -28,12 +28,12 @@
|
|
28
28
|
first = dates.sort_values()[0] # 最初の日
|
29
29
|
last = pd.Timestamp.now(dates.tz) # 同じタイムゾーンで今日の日付取得
|
30
30
|
|
31
|
-
#
|
31
|
+
# 日付 - 週の最初から数えた日数 = 週の最初の日 (月曜=0の場合)
|
32
32
|
begin = first - pd.to_timedelta(first.dayofweek, unit="d")
|
33
33
|
# 一番最後の日付の週の最後の日を取得する。
|
34
34
|
end = last + (pd.to_timedelta("6days") - pd.to_timedelta(last.dayofweek, unit="d"))
|
35
35
|
# ビンを作成
|
36
|
-
weeks = pd.date_range(begin, end, freq="W-MON")
|
36
|
+
weeks = pd.date_range(begin.floor("D"), end.floor("D"), freq="W-MON")
|
37
37
|
# ビン分割処理
|
38
38
|
ret = pd.cut(dates, weeks, right=False, include_lowest=False)
|
39
39
|
|
@@ -45,46 +45,47 @@
|
|
45
45
|
```
|
46
46
|
|
47
47
|
```
|
48
|
-
[2020-01-06
|
48
|
+
[2020-01-06, 2020-01-13) 2
|
49
|
-
[2020-01-13
|
49
|
+
[2020-01-13, 2020-01-20) 1
|
50
|
-
[2020-01-20
|
50
|
+
[2020-01-20, 2020-01-27) 1
|
51
|
-
[2020-01-27
|
51
|
+
[2020-01-27, 2020-02-03) 0
|
52
|
-
[2020-02-03
|
52
|
+
[2020-02-03, 2020-02-10) 1
|
53
|
-
[2020-02-10
|
53
|
+
[2020-02-10, 2020-02-17) 1
|
54
|
-
[2020-02-17
|
54
|
+
[2020-02-17, 2020-02-24) 0
|
55
|
-
[2020-02-24
|
55
|
+
[2020-02-24, 2020-03-02) 0
|
56
|
-
[2020-03-02
|
56
|
+
[2020-03-02, 2020-03-09) 1
|
57
|
-
[2020-03-09
|
57
|
+
[2020-03-09, 2020-03-16) 0
|
58
|
-
[2020-03-16
|
58
|
+
[2020-03-16, 2020-03-23) 0
|
59
|
-
[2020-03-23
|
59
|
+
[2020-03-23, 2020-03-30) 1
|
60
|
-
[2020-03-30
|
60
|
+
[2020-03-30, 2020-04-06) 0
|
61
|
-
[2020-04-06
|
61
|
+
[2020-04-06, 2020-04-13) 0
|
62
|
-
[2020-04-13
|
62
|
+
[2020-04-13, 2020-04-20) 1
|
63
|
-
[2020-04-20
|
63
|
+
[2020-04-20, 2020-04-27) 1
|
64
|
-
[2020-04-27
|
64
|
+
[2020-04-27, 2020-05-04) 0
|
65
|
-
[2020-05-04
|
65
|
+
[2020-05-04, 2020-05-11) 0
|
66
|
-
[2020-05-11
|
66
|
+
[2020-05-11, 2020-05-18) 0
|
67
|
-
[2020-05-18
|
67
|
+
[2020-05-18, 2020-05-25) 0
|
68
|
-
[2020-05-25
|
68
|
+
[2020-05-25, 2020-06-01) 0
|
69
|
-
[2020-06-01
|
69
|
+
[2020-06-01, 2020-06-08) 0
|
70
|
-
[2020-06-08
|
70
|
+
[2020-06-08, 2020-06-15) 0
|
71
|
-
[2020-06-15
|
71
|
+
[2020-06-15, 2020-06-22) 0
|
72
|
-
[2020-06-22
|
72
|
+
[2020-06-22, 2020-06-29) 0
|
73
|
-
[2020-06-29
|
73
|
+
[2020-06-29, 2020-07-06) 0
|
74
|
-
[2020-07-06
|
74
|
+
[2020-07-06, 2020-07-13) 0
|
75
|
-
[2020-07-13
|
75
|
+
[2020-07-13, 2020-07-20) 0
|
76
|
-
[2020-07-20
|
76
|
+
[2020-07-20, 2020-07-27) 0
|
77
|
-
[2020-07-27
|
77
|
+
[2020-07-27, 2020-08-03) 0
|
78
|
-
[2020-08-03
|
78
|
+
[2020-08-03, 2020-08-10) 0
|
79
|
-
[2020-08-10
|
79
|
+
[2020-08-10, 2020-08-17) 0
|
80
|
-
[2020-08-17
|
80
|
+
[2020-08-17, 2020-08-24) 0
|
81
|
-
[2020-08-24
|
81
|
+
[2020-08-24, 2020-08-31) 0
|
82
|
-
[2020-08-31
|
82
|
+
[2020-08-31, 2020-09-07) 0
|
83
|
-
[2020-09-07
|
83
|
+
[2020-09-07, 2020-09-14) 0
|
84
|
+
[2020-09-14, 2020-09-21) 0
|
84
85
|
dtype: int64
|
85
86
|
```
|
86
87
|
|
87
|
-
※ [2020-
|
88
|
+
※ [2020-09-07, 2020-09-14) の場合、左半開区間なので、2020-09-07, 2020-09-13 を意味します。
|
88
89
|
|
89
90
|
[pandas - 日時や期間の情報を取得する dt accessor の使い方](https://pystyle.info/pandas-dt-accessor/)
|
90
91
|
[pandas - cut、qcut でビン分割を行う方法](https://pystyle.info/pandas-how-to-binning/)
|
1
修正
answer
CHANGED
@@ -84,4 +84,7 @@
|
|
84
84
|
dtype: int64
|
85
85
|
```
|
86
86
|
|
87
|
-
※ [2020-01-06 12:03:24, 2020-01-13 12:03:24) の場合、左半開区間なので、2020-01-06 ~ 2020-01-12 を意味します。
|
87
|
+
※ [2020-01-06 12:03:24, 2020-01-13 12:03:24) の場合、左半開区間なので、2020-01-06 ~ 2020-01-12 を意味します。
|
88
|
+
|
89
|
+
[pandas - 日時や期間の情報を取得する dt accessor の使い方](https://pystyle.info/pandas-dt-accessor/)
|
90
|
+
[pandas - cut、qcut でビン分割を行う方法](https://pystyle.info/pandas-how-to-binning/)
|