回答編集履歴

1

サンプルを追加

2018/06/05 09:32

投稿

magichan
magichan

スコア15898

test CHANGED
@@ -49,3 +49,35 @@
49
49
  #Name: x1,dtype: float64
50
50
 
51
51
  ```
52
+
53
+
54
+
55
+ ---
56
+
57
+ **【追記】**
58
+
59
+
60
+
61
+ 新しいフレームワークを作成するサンプル
62
+
63
+
64
+
65
+ ```Python
66
+
67
+ df_new = df2.groupby((df2.x2 != 0).cumsum()).apply(lambda d:pd.Series([d.index[0], d.index[-1], d['x1'].mean()],index=['start','end','mean_x1']))
68
+
69
+ print(df_new)
70
+
71
+ # start end mean_x1
72
+
73
+ #x2
74
+
75
+ #1 2017-07-01 00:00:00 2017-07-01 05:00:00 13.433333
76
+
77
+ #2 2017-07-01 06:00:00 2017-07-01 10:00:00 13.860000
78
+
79
+ #3 2017-07-01 11:00:00 2017-07-01 15:00:00 13.000000
80
+
81
+ #4 2017-07-01 16:00:00 2017-07-01 20:00:00 14.800000
82
+
83
+ ```