mirror of
https://github.com/webclinic017/drift.git
synced 2026-08-21 14:58:11 +00:00
feat(Data): resample exogenous/other datasource when their frequency is different (#234)
* feat(Data): resample exogenous/other datasource when their frequency is different * fix(Linter): ran * fix(Data): resampling done properly
This commit is contained in:
+10
-4
@@ -3,8 +3,14 @@ import pandas as pd
|
||||
|
||||
def resample_ohlc(df, period):
|
||||
output = pd.DataFrame()
|
||||
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()
|
||||
period = period.replace("m", "T")
|
||||
|
||||
if "open" in df.columns:
|
||||
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()
|
||||
else:
|
||||
output = df.resample(period).ffill()
|
||||
|
||||
return output
|
||||
|
||||
Reference in New Issue
Block a user