Spaces:
Sleeping
Sleeping
File size: 1,002 Bytes
79e1719 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 |
"""
Stores all transformations
"""
def createLag(data, amt=10):
"""
Create a lag inside dataframe, in business days
:param pandas.DataFrame data:
:param int amt: Unit of lag period
:return: Copy of pandas Dataframe
"""
import pandas as pd
if 'ds' in data:
copy = data.copy()
copy['ds'] = copy['ds'] + pd.tseries.offsets.BusinessDay(amt)
return copy
else:
print(f"No 'ds' column found inside dataframe")
return data
def scaleStandard(df_col):
"""
Fits and returns a standard scaled version of a dataframe column
"""
import pandas as pd
from sklearn.preprocessing import StandardScaler
scaler = StandardScaler()
df_col = scaler.fit_transform(df_col)
df_col = pd.DataFrame(df_col)
return df_col, scaler
def logReturn(data, df_col):
"""
Perform log return for a dataframe column
"""
import numpy as np
new_col = np.log1p(data[df_col].pct_change())
return new_col |