回答編集履歴

2

追記

2018/06/06 20:10

投稿

hayataka2049
hayataka2049

スコア30933

test CHANGED
@@ -65,3 +65,65 @@
65
65
  参考:
66
66
 
67
67
  [pandas.DataFrame.groupby — pandas 0.23.0 documentation](https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html)
68
+
69
+
70
+
71
+ ### 追記
72
+
73
+ とりあえずdatetime.timeにしてみました。
74
+
75
+
76
+
77
+ ```python
78
+
79
+ import io
80
+
81
+ import datetime
82
+
83
+ import pandas as pd
84
+
85
+
86
+
87
+ # ただの読み込み処理
88
+
89
+ data = """
90
+
91
+ 2018-05-28 18:01:00 100 200
92
+
93
+ 2018-05-28 18:05:00 100 200
94
+
95
+ 2018-05-28 19:08:00 100 200
96
+
97
+ 2018-05-28 19:01:00 100 200
98
+
99
+ 2018-05-29 18:01:00 100 200
100
+
101
+ 2018-05-29 18:05:00 100 200
102
+
103
+ 2018-05-29 19:08:00 100 200
104
+
105
+ 2018-05-29 19:01:00 100 200
106
+
107
+ """
108
+
109
+ df = pd.read_table(io.StringIO(data), header=None, index_col=0)
110
+
111
+ df.index = pd.to_datetime(df.index)
112
+
113
+
114
+
115
+ # 回答
116
+
117
+ print(df.groupby(lambda x:datetime.time(hour=x.hour)).sum())
118
+
119
+ """ =>
120
+
121
+ 1 2
122
+
123
+ 18:00:00 400 800
124
+
125
+ 19:00:00 400 800
126
+
127
+ """
128
+
129
+ ```

1

結果を書いておこう

2018/06/06 20:10

投稿

hayataka2049
hayataka2049

スコア30933

test CHANGED
@@ -44,7 +44,21 @@
44
44
 
45
45
  print(df.groupby(lambda x:x.hour).sum())
46
46
 
47
+ """ =>
48
+
49
+ 1 2
50
+
51
+ 18 400 800
52
+
53
+ 19 400 800
54
+
55
+ """
56
+
47
57
  ```
58
+
59
+
60
+
61
+ これだとindexがintなのが微妙といえば微妙かも・・・
48
62
 
49
63
 
50
64