1
我有一個數據幀,用下面的代碼生成:DatetimeIndex抵消
time_index = pd.date_range(start=datetime(2013, 1, 1, 3),
end=datetime(2013, 1, 2, 2, 59),
freq='5T')
grid_columns = [u'in_brd', u'in_alt', u'out_brd', u'out_alt']
grid_proto = pd.DataFrame(index=time_index, columns=grid_columns)
我還添加了一些數據,這個數據幀。
當我試圖通過在數據幀的基本抵消int
指數瀏覽我得到寄託都正確:
In[152]: grid_proto.index[0] + 1
Out[152]: Timestamp('2013-01-01 03:05:00', tz=None)
但是,如果我試圖用某種片的工作,我得到一個錯誤:
In[153]: z = grid_proto[pd.notnull(x.in_brd)]
In[154]: z.index[0] + 1
Traceback (most recent call last):
File "<ipython-input-151-3ce8a4e5e2d6>", line 1, in <module>
z.index[0] + 1
File "tslib.pyx", line 664, in pandas.tslib._Timestamp.__add__ (pandas\tslib.c:12372)
ValueError: Cannot add integral value to Timestamp without offset.
我明白,這是因爲在第一種情況下我一個鏈接工作DatetimeIndex
元素,而不是標量。而在第二種情況下,我會得到第一個索引元素的確切標量Timestamp
的值。我對嗎?
如何正確處理這個偏移量? (我需要通過這樣的切片導航)