什么是索引时间序列中相对时间片段的正确方法?

2024-04-25 08:52:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我想查看一个时间序列的30秒片段,我有兴趣选择那些相对于时间序列开始的片段。以下是正确的方法,还是有更标准的方法?你知道吗

import pandas as pd
import datetime as dt
import numpy as np

dft = pd.DataFrame(np.random.randn(600, 1), columns=['A'],
                   index=pd.date_range('20130101', periods=600, freq='S'))

timestart = dft[0:1].index[0]
timeend = timestart + dt.timedelta(seconds=30)

dft[timestart:timeend].plot()

Tags: 方法importpandas标准indexasnp时间