【发布时间】:2023-03-11 18:25:01
【问题描述】:
我有 CSV 格式的时间序列数据。我想在脚本的单次运行中计算不同选定时间段的平均值,例如01-05-2017: 30-04-2018, 01-05-2018: 30-04-2019 等等。以下是样本数据
我有一个脚本,但它只需要一个给定的时间段。但我想给出上面提到的多个时间段。
from datetime import datetime
import pandas as pd
df = pd.read_csv(r'D:\Data\RT_2015_2020.csv', index_col=[0],parse_dates=[0])
z = df['2016-05-01' : '2017-04-30']
# Want to make like this way
#z = df[['2016-05-01' : '2017-04-30'], ['2017-05-01' : '2018-04-30']]
# It will calculate the mean for the selected time period
z.mean()
【问题讨论】:
-
可能的重复/相关问题:stackoverflow.com/questions/39393856/…
-
我试过了,但是不行
标签: python pandas time-series