5 examples of 'pandas transform' in Python

Every line of 'pandas transform' code snippets is scanned for vulnerabilities by our powerful machine learning engine that combs millions of open source libraries, ensuring your Python code is secure.

All examples are scanned by Snyk Code

By copying the Snyk Code Snippets you agree to
this disclaimer
51def transform(self, X, columns=None):
52 self._check_input(X)
53 x_type = type(X)
54
55 if x_type == MultiSeries:
56 return self._transform_series(X)
57
58 # If X is not MultiSeries, then it's MultiDataFrame
59 # Because of self._check_input function
60 return self._transform_data_frame(X)
Important

Use secure code every time

Secure your code as it's written. Use Snyk Code to scan source code in minutes – no build needed – and fix issues immediately. Enable Snyk Code

140def transform(self, X, columns_mapping=None):
141 '''
142 Transform X with fitted dictionary self.transformations.
143 :param columns_mapping: {old_col: new_col} mapping between columns in fit data set and current X
144 :return:
145 '''
146 if columns_mapping is None:
147 columns_mapping = {}
148
149 transformers_df = X.copy()
150
151 for col_name, transformations in self.transformations.items():
152 for t in transformations:
153 new_col_name = columns_mapping.get(col_name, col_name)
154 transformed_column = t.transform(X[new_col_name])
155
156 if type(transformed_column) == XSeries:
157 transformers_df.rename(columns={
158 new_col_name: transformed_column.name
159 }, inplace=True)
160 transformers_df[transformed_column.name] = transformed_column
161 else:
162 transformers_df.drop(new_col_name, inplace=True, axis=1)
163
164 transformers_df = XDataFrame.concat_dataframes(
165 [transformers_df, transformed_column]
166 )
167
168 return transformers_df
44def transform(self, data):
45 """User implements internal transform function which operates on a single data element from a data_object
46
47 Args:
48 data (object): input data
49
50 Returns:
51 data, transformed
52
53 """
54 if isinstance(data, pd.DataFrame):
55 if self.columns:
56 scaled_features_df = data.copy()
57
58 # transform select columns
59 scaled_features = self.preprocessor.transform(data[self.columns].values)
60 for idx, colname in enumerate(self.columns):
61 scaled_features_df[colname] = scaled_features[:,idx]
62
63 else:
64 scaled_features = self.preprocessor.transform(data.values)
65 try:
66 scaled_features_df = pd.DataFrame(scaled_features, index=data.index, columns=data.columns)
67 except ValueError:
68 logging.info(f'{self.preprocessor.__class__.__name__} instance changed the number of columns. Returning raw values')
69 return pd.DataFrame(scaled_features)
70 return scaled_features_df
71
72 return self.preprocessor.transform(data)
250def _transform(self, dataset):
251 self._transfer_params_to_java()
252 return DataFrame(self._java_obj.transform(dataset._jdf), dataset.sql_ctx)
7def dataframe_transform_parallel(
8 df, transformer
9 ):
10 cpu_count = multiprocessing.cpu_count()
11 workers_count = int(round(cpu_count))
12 logger.log(15, 'Dataframe_transform_parallel running pool with '+str(workers_count)+' workers')
13 df_chunks = np.array_split(df, workers_count)
14 df_list = execute_multiprocessing(workers_count=workers_count, transformer=transformer, chunks=df_chunks)
15 df_combined = pd.concat(df_list, axis=0, ignore_index=True)
16 return df_combined

Related snippets