Python 无法使用这些索引器对DatetimeIndex进行位置索引

Python 无法使用这些索引器对DatetimeIndex进行位置索引,python,pandas,datetime,indexing,Python,Pandas,Datetime,Indexing,我有一个带有日期时间索引的时间序列数据帧“his”,我想从中提取一定范围的时间步长。起始点“selected_var_start”采用日期时间索引格式(从另一个数据帧中提取)。我想在24小时内提取 我试着这样做:his=his.iloc[selected\u var\u start:(selected\u var\u start+pd.DateOffset(hours=24))] 我得到以下错误TypeError:无法使用这些类型为DatetimeIndex的索引器[DatetimeIndex(

我有一个带有日期时间索引的时间序列数据帧“his”,我想从中提取一定范围的时间步长。起始点“selected_var_start”采用日期时间索引格式(从另一个数据帧中提取)。我想在24小时内提取

我试着这样做:
his=his.iloc[selected\u var\u start:(selected\u var\u start+pd.DateOffset(hours=24))]

我得到以下错误
TypeError:无法使用这些类型为DatetimeIndex的索引器[DatetimeIndex(['2010-11-12 19:00:00'],dtype='datetime64[ns]',name='Datetime',freq=None])对DatetimeIndex进行位置索引


我做错了什么?

使用带字符串的
loc

pd.DataFrame(index=pd.date_range('11/01/2010', '12/01/2010')).loc['2010-11-12': '2010-11-13']

用于“基于位置选择的纯整数位置索引”-请改用。如果我使用
his=his.loc[selected\u var\u start:(selected\u var\u start+pd.DateOffset(hours=24))
I获得“pandas.errors.InvalidIndexError:DatetimeIndex(['2010-11-12 19:00:00'],dtype='datetime64[ns]',name='Datetime',freq=None)”,这只是一般建议;如果你需要一个详细的答案,请提供一个答案。我可以包括时间吗?我想我必须使用selected_var_start.strftime(dateformat),但我看起来只能使用日期,不能使用时间?