out_cols = X.columns.values
for col in cols:
col_list = [col0 for col0 in out_cols if str(col0).startswith(str(col))]
prefix_length = len(str(col))+1 // original column name plus underscore
if self.use_cat_names:
X[col] = 0
for tran_col in col_list:
val = tran_col[prefix_length:]
X.loc[X[tran_col] == 1, col] = val
else:
value_array = np.array([int(col0[prefix_length:]) for col0 in col_list])
X[col] = np.dot(X[col_list].values, value_array.T)
out_cols = [col0 for col0 in out_cols if col0 not in col_list]
X = X.reindex(columns=out_cols + cols)
After Change
existing_col = column_mapping.get("new_col_name")
val = column_mapping.get("val")
X.loc[X[existing_col] == 1, col] = val
mapped_columns.append(existing_col)
out_cols = [col0 for col0 in out_cols if col0 not in mapped_columns]
return X.reindex(columns=out_cols + cols)