我有一个带有datetime索引的时间序列数据帧"his“,我想从中提取一定范围的时间步长。起始点"selected_var_start“是datetime索引格式(从另一个数据帧中提取)。我想提取总共24小时。
我试着这样做:his = his.iloc[selected_var_start:(selected_var_start+pd.DateOffset(hours=24))]
我得到以下错误TypeError: cannot do positional indexing on DatetimeIndex with these indexers [DatetimeIndex(['2010-11-12 19:00:00'], dtype='datetime64[ns]', name='Datetime', freq=None)] of type DatetimeIndex
我做错了什么?
发布于 2021-06-01 21:35:41
将loc与字符串一起使用
pd.DataFrame(index=pd.date_range('11/01/2010', '12/01/2010')).loc['2010-11-12': '2010-11-13']https://stackoverflow.com/questions/67789837
复制相似问题