2022-02-17 16:36:35 +01:00
|
|
|
import pandas as pd
|
|
|
|
|
|
2022-02-17 19:22:17 +01:00
|
|
|
|
2022-02-17 16:36:35 +01:00
|
|
|
def resample_ohlc(df, period):
|
|
|
|
|
output = pd.DataFrame()
|
2022-03-12 22:22:10 +01:00
|
|
|
output["open"] = df.open.resample(period).first()
|
|
|
|
|
output["high"] = df.high.resample(period).max()
|
|
|
|
|
output["low"] = df.low.resample(period).min()
|
|
|
|
|
output["close"] = df.close.resample(period).last()
|
|
|
|
|
return output
|
|
|
|
|
|
2022-03-10 20:00:06 +01:00
|
|
|
|
2022-03-12 22:22:10 +01:00
|
|
|
def upsample(df, period):
|
|
|
|
|
output = pd.DataFrame()
|
|
|
|
|
period = period.replace("m", "T")
|
|
|
|
|
output = df.resample(period).ffill()
|
2022-03-10 20:00:06 +01:00
|
|
|
|
2022-02-17 19:22:17 +01:00
|
|
|
return output
|