2017-06-01 16 views
0

我有具有以下數據的表:PerformanceWarning:加/減DateOffsets到系列的陣列不向量化「系列不向量化」,PerformanceWarning)

StudentID LO_0 LO_1 
0 student001 2017-02-07T16:37:57 2017-01-21T15:32:46 
11 student015 2017-02-07T15:32:09 2017-01-03T21:15:33 
56 student072 2017-02-07T19:59:46 2017-02-06T14:03:57 
63 student079 2017-02-04T16:52:43 2017-01-23T10:00:27 

當我發行下文從jupyter「記事本」命令,則我得到預期的結果

df_test['Delta_t']= abs((df_test.loc[:,item1] - df_test.loc[:,item2]).astype('timedelta64[h]').astype('int')) 

    Delta_t 
    409 
    834 
    29 
    294 

但是當我運行從一個Python腳本這個相同的命令,我獲得以下性能警告和錯誤的相同的命令:

anaconda/lib/python3.5/site-packages/pandas/core/ops.py:477: PerformanceWarning: Adding/subtracting array of DateOffsets to Series not vectorized "Series not vectorized", PerformanceWarning) 

錯誤

TypeError: ufunc subtract cannot use operands with types dtype('<M8[ns]') and dtype('O') 
+0

[沒有幫助?(https://stackoverflow.com/a/44318465/5741205) – MaxU

+0

這沒有發生,再次收到同樣的錯誤 – gaurav1207

回答

0
In [172]: df['Delta_t'] = ((df.LO_0 - df.LO_1).dt.total_seconds()/3600).astype(int) 

In [173]: df 
Out[173]: 
    StudentID    LO_0    LO_1 Delta_t 
0 student001 2017-02-07 16:37:57 2017-01-21 15:32:46  409 
11 student015 2017-02-07 15:32:09 2017-01-03 21:15:33  834 
56 student072 2017-02-07 19:59:46 2017-02-06 14:03:57  29 
63 student079 2017-02-04 16:52:43 2017-01-23 10:00:27  294