Skip to content

Commit be4714d

Browse files
author
florian
committed
Reapplied lost fix for BaseNEncoder
1 parent 07bd4a2 commit be4714d

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

category_encoders/basen.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -349,21 +349,20 @@ def basen_to_integer(self, X, cols, base):
349349
-------
350350
numerical: DataFrame
351351
"""
352-
out_cols = X.columns.values
352+
out_cols = X.columns.values.tolist()
353353

354354
for col in cols:
355355
col_list = [col0 for col0 in out_cols if str(col0).startswith(str(col))]
356+
insert_at = out_cols.index(col_list[0])
356357

357358
if base == 1:
358359
value_array = np.array([int(col0.split('_')[-1]) for col0 in col_list])
359360
else:
360361
len0 = len(col_list)
361362
value_array = np.array([base ** (len0 - 1 - i) for i in range(len0)])
362-
363-
X[col] = np.dot(X[col_list].values, value_array.T)
364-
out_cols = [col0 for col0 in out_cols if col0 not in col_list]
365-
366-
X = X.reindex(columns=out_cols + cols)
363+
X.insert(insert_at,col,np.dot(X[col_list].values, value_array.T))
364+
X.drop(col_list, axis=1, inplace=True)
365+
out_cols = X.columns.values.tolist()
367366

368367
return X
369368

0 commit comments

Comments
 (0)