繁体   English   中英

Pandas 使用 Datetimeindex 和 loc

[英]Pandas using Datetimeindex and loc

我正在使用loc在某些条件下获取索引。 然后我获取这些索引的时间增量并尝试使用这两个索引再次访问我的 dataframe。 我收到以下错误:

“无法转换 <class 'pandas.core 类型的输入 [DatetimeIndex(['2018-03-16 17:59:00'], dtype='datetime64[ns]', name='Zeitstempel', freq=None)] .indexes.datetimes.DatetimeIndex'> 到时间戳"

我的代码:

idx_open = df.loc[(df.Status == 'SR_OPEN')&(df.count_open == 1)&(df.count_close == 0)].index
n = 100
window = pd.Timedelta('15min')

begin = idx_open[n:n+1]
begin_1 = begin - window
begin_2 = begin + window
df.loc[begin_1:begin_2]

没有更多信息,这似乎是一个类型问题。 尝试投下你的日期:

begin_1 = pd.to_datetime(begin) - window
begin_2 = pd.to_datetime(begin) + window
df.loc[begin_1:begin_2]

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM