0
我有一個數據幀爲: 數據幀的索引是時間對象,一列被命名爲'空閒時間'作爲某個數值。如何擬合python中的時間序列數據的多項式
14:09:00 1644
14:22:35 321
14:25:17 498
14:26:10 195
14:28:22 216
14:31:58 101
14:32:07 268
14:36:26 154
14:40:26 160
14:42:46 3085
14:45:21 172
14:50:29 71
14:51:14 594
14:52:03 79
14:55:32 130
14:55:39 69
14:57:29 80
14:58:15 68
14:59:57 78
15:02:15 112
15:03:09 191
15:04:10 537
15:04:26 85
15:04:45 65
15:05:20 223
15:07:28 95
15:13:26 117
15:13:39 176
15:15:22 73
15:15:30 70
... ...
16:08:29 181
16:09:47 137
16:10:28 345
16:12:10 138
16:14:34 65
16:15:00 104
16:15:41 65
16:16:40 91
16:16:43 415
16:17:36 302
16:18:12 2478
16:19:17 644
16:24:19 654
16:24:52 163
16:25:32 276
16:29:08 65
16:29:23 72
16:30:19 65
16:32:10 79
16:32:56 85
16:34:32 90
16:34:41 1261
16:34:52 65
16:38:13 277
16:40:06 155
16:43:11 110
16:50:57 1190
16:52:59 142
16:56:30 756
17:00:02 116
[102 rows x 1 columns]
我想爲這個數據擬合一個最佳多項式來預測下一個30分鐘的空閒時間。我已經使用polyfit函數來擬合多項式。但我得到這個錯誤:
TypeError: unsupported operand type(s) for +: 'datetime.time' and 'float'
任何人都可以建議這裏有什麼問題。我的代碼是:
Idletimes=pd.DataFrame(SampleOne, index=Times, columns=['Idle_duration'])
Idletimes.sort_index(inplace=True)
z = np.polyfit(Idletimes.index, Idletimes['Idle_duration'], 2)
print(z)
將您的時間戳轉換爲更明智的內容,例如秒(無論您的零點是什麼)。 – Evert