Created
February 19, 2021 06:07
-
-
Save zredlined/44ebfb23207650710eecf518be231eed to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def trends_only(source_df: pd.DataFrame, trend_col: str) -> (float, pd.DataFrame): | |
""" Extract trends as training features vs total volume """ | |
df = source_df.copy() | |
start_val = df.at[0, trend_col] | |
df.sin = df[[trend_col]].diff() | |
df.at[0, trend_col] = 0.00 | |
return start_val, df | |
def restore_daily(source_df: pd.DataFrame, start_val: float, trend_col: str): | |
""" Restore daily cumulative values from trend data """ | |
df = source_df.copy() | |
df.at[0, trend_col] = start_val | |
df[trend_col] = df[trend_col].cumsum() | |
df[trend_col] = df[trend_col].apply(pd.to_numeric, downcast='float', errors='coerce').round(2) | |
df.dropna(inplace=True) | |
return df | |
# Extract trends from timeseries column to create training set | |
start_val, trends_df = trends_only(train_df, trend_col) | |
trends_df |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment