I have a pandas dataframe df
:
Out[16]:
<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 269850 entries, 2012-12-19 16:15:36 to 2012-12-20 14:36:55
Data columns:
X1 269850 non-null values
X2 269848 non-null values
X3 269848 non-null values
dtypes: float64(2), object(1)
And I would like to slice the dataframe to return a four hour window of data from 2012-12-20 05:00:00
to 2012-12-20 09:00:00
When I try:
Slicedf = df.truncate(before='12/20/2012 05:00:00',after='12/20/2012 09:00:00')
The following error occurs:
KeyError: datetime.datetime(2012, 12, 20, 5, 0)
I have also tried (from Pandas DataFrame slicing by day/hour/minute):
from datetime import datetime
x=datetime(2012,12,20,5,0,0)
y=datetime(2012,12,20,9,0,0)
Slicedf = df.ix[x:y]
which returns the exact same error.