MCPcopy Create free account
hub / github.com/ScottfreeLLC/AlphaPy / apply_transform

Function apply_transform

alphapy/features.py:114–148  ·  view source on GitHub ↗

r"""Apply a transform function to a column of the dataframe. Parameters ---------- fname : str Name of the column to be treated in the dataframe ``df``. df : pandas.DataFrame Dataframe containing the column ``fname``. fparams : list The module, function,

(fname, df, fparams)

Source from the content-addressed store, hash-verified

112#
113
114def apply_transform(fname, df, fparams):
115 r"""Apply a transform function to a column of the dataframe.
116
117 Parameters
118 ----------
119 fname : str
120 Name of the column to be treated in the dataframe ``df``.
121 df : pandas.DataFrame
122 Dataframe containing the column ``fname``.
123 fparams : list
124 The module, function, and parameter list of the transform
125 function
126
127 Returns
128 -------
129 new_features : pandas.DataFrame
130 The set of features after applying a transform function.
131
132 """
133 # Extract the transform parameter list
134 module = fparams[0]
135 func_name = fparams[1]
136 plist = fparams[2:]
137 # Append to system path
138 sys.path.append(os.getcwd())
139 # Import the external transform function
140 ext_module = import_module(module)
141 func = getattr(ext_module, func_name)
142 # Prepend the parameter list with the data frame and feature name
143 plist.insert(0, fname)
144 plist.insert(0, df)
145 # Apply the transform
146 logger.info("Applying function %s from module %s to feature %s",
147 func_name, module, fname)
148 return func(*plist)
149
150
151#

Callers 1

apply_transformsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected