2016-05-09 132 views
2

我正在與不同的熊貓索引格式掙扎。熊貓指定日期時間索引的時間範圍

我的單變量時間序列(數據)看起來像這樣

2015-01-01 22:00:01.973 1.210525 
2015-01-01 22:00:03.297 1.210490 
2015-01-01 22:00:23.922 1.210485 
2015-01-01 22:00:24.507 1.210480 
2015-01-01 22:01:05.979 1.210490 
2015-01-01 22:01:08.390 1.210525 
2015-01-01 22:01:09.899 1.210520 
2015-01-01 22:01:09.950 1.210505 
2015-01-01 22:01:13.576 1.210505 
2015-01-01 22:01:19.984 1.210485 
2015-01-01 22:01:27.936 1.210510 

其中

>>> type(data) 
<class 'pandas.core.series.Series'> 
>>> type(data.index) 
<class 'pandas.tseries.index.DatetimeIndex'> 
>>> 

我有提取起點和終點的功能,說

>>>start 
textdate 
2015-01-01 22:00:03.297 1.210490 
Name: mean, dtype: float64 
>>> 

>>>end 
textdate 
2015-01-01 22:01:19.984 1.210485 
Name: mean, dtype: float64 
>>> 

如何根據似乎是DatetimeIndex的索引值從頭到尾對系列進行分片墊本身作爲

>>> start.index 
DatetimeIndex(['2015-01-01 22:00:03.297'], dtype='datetime64[ns]', name=u'textdate', freq=None) 
>>> 

我想這

series = data[start.index : end.index] 

這給了我

TypeError: Cannot convert input to Timestamp 

但我無法轉換的DatetimeIndex對象開始和結束到時間戳...

+1

不'data.loc [start.index:end.index]'工作? – EdChum

+0

與data.loc相同的錯誤[012] – Pat

+1

確定'data.loc [start.index [0]:end.index [0]]''怎麼樣? – EdChum

回答

1

您需要訪問單列Series內的標值,並通過這loc裁DF:

data.loc[start.index[0] : end.index[0]] 
1

我認爲您在切片中使用的是對Series的引用。相反,嘗試:

series = data[start.index[0] : end.index[0]] 

我覺得你startend是單期系列。

相關問題