adds nan replacement to scale transformation
@@ -9,12 +9,28 @@ from .base import Transformation
class scale(Transformation):
+ ''' Scale a variable.
- def _transform(self, data, demean=True, rescale=True):
+ Args:
+ data (Series/DF): The variables to scale.
+ demean (bool): If True, demean each column.
+ rescale (bool): If True, divide variables by their standard deviation.
+ replace_na (str): Whether/when to replace missing values with 0. If
+ None, no replacement is performed. If 'before', missing values are
+ replaced with 0's before scaling. If 'after', missing values are
+ replaced with 0 after scaling.
+
+ '''
+
+ def _transform(self, data, demean=True, rescale=True, replace_nan=None):
+ if replace_nan == 'before':
+ data = data.fillna(0.)
if demean:
data -= data.mean()
if rescale:
data /= data.std()
+ if replace_nan == 'after':
+ data = data.fillna(0.)
return data
@@ -79,6 +95,7 @@ class orthogonalize(Transformation):
class threshold(Transformation):
''' Threshold and/or binarize a variable.
+
Args:
data (Series/DF): The pandas structure to threshold.
threshold (float): The value to binarize around (values above will
@@ -114,6 +131,7 @@ class threshold(Transformation):
class or_(Transformation):
''' Logical OR (inclusive) on two or more variables.
+
Args:
dfs (list of DFs): variables to enter into the disjunction.
'''
@@ -129,6 +147,7 @@ class or_(Transformation):
class not_(Transformation):
''' Logical negation of a variable.
+
Args:
var (Series): Variable to negate. Must be convertible to bool.
'''
@@ -142,6 +161,7 @@ class not_(Transformation):
class and_(Transformation):
''' Logical AND on two or more variables.
+
Args:
dfs (list of DFs): variables to enter into the conjunction.
'''
