回答編集履歴
1
追記
test
CHANGED
@@ -1,3 +1,47 @@
|
|
1
1
|
``aggregation = {'visitors' : 'median'}``で良さそうな気がします。
|
2
2
|
|
3
3
|
元のデータを見ていないので違っていたらすみません。
|
4
|
+
|
5
|
+
|
6
|
+
|
7
|
+
---
|
8
|
+
|
9
|
+
|
10
|
+
|
11
|
+
【追記】データで試した結果です。
|
12
|
+
|
13
|
+
```Python
|
14
|
+
|
15
|
+
import pandas as pd
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
air_data = pd.read_csv('air_visit_data.csv', parse_dates=['visit_date'])
|
20
|
+
|
21
|
+
air_data['dow'] = air_data['visit_date'].dt.dayofweek
|
22
|
+
|
23
|
+
train = air_data[air_data['visit_date'] > '2017-01-28'].reset_index()
|
24
|
+
|
25
|
+
train['dow'] = train['visit_date'].dt.dayofweek
|
26
|
+
|
27
|
+
aggregation = {'visitors' : 'median'}
|
28
|
+
|
29
|
+
agg_data = train.groupby(['air_store_id', 'dow']).agg(aggregation).reset_index()
|
30
|
+
|
31
|
+
agg_data.head()
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
#air_store_id dow visitors
|
36
|
+
|
37
|
+
#0 air_00a91d42b08b08d9 0 24.0
|
38
|
+
|
39
|
+
#1 air_00a91d42b08b08d9 1 30.5
|
40
|
+
|
41
|
+
#2 air_00a91d42b08b08d9 2 28.0
|
42
|
+
|
43
|
+
#3 air_00a91d42b08b08d9 3 33.5
|
44
|
+
|
45
|
+
#4 air_00a91d42b08b08d9 4 37.0
|
46
|
+
|
47
|
+
```
|