我正在处理股票价格数据,并希望resample()每第二行而不是每第二个工作日返回一次 ( resample('2B'))。障碍是任何在工作日登陆的假期。见下文,MLK 日是 2018 年 1 月 15 日星期一:
import pandas as pd
data = '''\
date,price
2018-01-08,88.28
2018-01-09,88.22
2018-01-10,87.82
2018-01-11,88.08
2018-01-12,89.6
2018-01-16,88.35
2018-01-17,90.14
2018-01-18,90.1
2018-01-19,90.0
2018-01-22,91.61
2018-01-23,91.9
2018-01-24,91.82
2018-01-25,92.33
2018-01-26,94.06'''
fileobj = pd.compat.StringIO(data)
df = pd.read_csv(fileobj, parse_dates=['date'], index_col=[0])
df_resample = df.resample('2B').min()
print(df_resample)
输出:
price
2018-01-08 88.22
2018-01-10 87.82
2018-01-12 89.60
2018-01-16 88.35
2018-01-18 90.00
2018-01-22 91.61
2018-01-24 91.82
2018-01-26 94.06
我希望重新采样从 1/12 跳到 1/17。我知道我可以使用df['price'].loc[::2]来交付df.resample('2B').last(),但我需要使用min(),max()并且sum()也一样。
谢谢。
预期输出:
