简体   繁体   English

时间序列数据提取

[英]Time series data extraction

I have data set in format given bellow.我有下面给出的格式的数据集。 I am interested to extract data points every after 3H.我有兴趣在 3H 之后提取数据点。

   Unnamed: 0                Date  ...  a_anox1  a_anox2
0           0 2017-11-01 00:00:41  ...   3.6465      0.0
1           1 2017-11-01 00:01:41  ...   3.9795      0.0
2           2 2017-11-01 00:02:41  ...   4.2055      0.0
3           3 2017-11-01 00:03:41  ...   4.4490      0.0
4           4 2017-11-01 00:04:41  ...   4.6375      0.0

[5 rows x 12 columns]

I want to extract data points every after 3H the outputs:我想在输出 3H 后提取数据点:

   Unnamed: 0                Date  
0           0 2017-11-01 00:00:41  
1           1 2017-11-01 03:00:41 
2           2 2017-11-01 06:00:41  
3           3 2017-11-01 09:00:41  
4           4 2017-11-01 12:00:41  

[5 rows x 12 columns]

Use resample .使用resample Set your datetime column to index df.set_index('date_column', inplace=True) and then use resample :将您的日期时间列设置为索引df.set_index('date_column', inplace=True)然后使用resample

import pandas as pd

# data with hours differe 
df = pd.DataFrame({'symbol':range(13)}, index=pd.date_range(start='01-12-2020', freq='H', periods=13))   

# example data get 3rd hour last value
last3h = df.resample('3H').last()   

print(last3h)

See resample in Pandas documentation for more details and use cases.有关更多详细信息和用例,请参阅Pandas 文档中的重新采样。

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

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