@@ -663,7 +663,12 @@ define([
663
663
} ) ;
664
664
}
665
665
666
- // Render Inner popup page
666
+ /**
667
+ * Render Inner popup page
668
+ * @param {* } type
669
+ * @param {* } targetLabel
670
+ * @returns
671
+ */
667
672
renderAddPage = function ( type , targetLabel = '' ) {
668
673
var content = new com_String ( ) ;
669
674
content . appendFormatLine ( '<div class="{0}">' , 'vp-inner-popup-addpage' ) ;
@@ -682,7 +687,9 @@ define([
682
687
content . appendFormatLine ( '<td><select class="{0}">' , 'vp-inner-popup-addtype' ) ;
683
688
content . appendFormatLine ( '<option value="{0}">{1}</option>' , 'value' , 'Value' ) ;
684
689
content . appendFormatLine ( '<option value="{0}">{1}</option>' , 'calculation' , 'Calculation' ) ;
685
- content . appendFormatLine ( '<option value="{0}">{1}</option>' , 'replace' , 'Replace' ) ;
690
+ if ( type == 'replace' ) {
691
+ content . appendFormatLine ( '<option value="{0}">{1}</option>' , 'replace' , 'Replace' ) ;
692
+ }
686
693
if ( type == 'column' || type == 'replace' ) {
687
694
content . appendFormatLine ( '<option value="{0}">{1}</option>' , 'subset' , 'Subset' ) ;
688
695
}
@@ -1245,6 +1252,17 @@ define([
1245
1252
code . appendFormat ( "{0} = vp_drop_outlier({1}, {2})" , tempObj , tempObj , selectedName ) ;
1246
1253
}
1247
1254
break ;
1255
+ case FRAME_EDIT_TYPE . LABEL_ENCODING :
1256
+ if ( axis == FRAME_AXIS . COLUMN ) {
1257
+ let encodedColName = this . state . selected . map ( col => {
1258
+ if ( col . code !== col . label ) {
1259
+ return com_util . formatString ( "'{0}'" , col . label + '_label' ) ;
1260
+ }
1261
+ return col . label + '_label'
1262
+ } ) . join ( ',' ) ;
1263
+ code . appendFormat ( "{0}[{1}] = pd.Categorical({2}[{3}]).codes" , tempObj , encodedColName , tempObj , selectedName ) ;
1264
+ }
1265
+ break ;
1248
1266
case FRAME_EDIT_TYPE . ONE_HOT_ENCODING :
1249
1267
if ( axis == FRAME_AXIS . COLUMN ) {
1250
1268
code . appendFormat ( "{0} = pd.get_dummies(data={1}, columns=[{2}])" , tempObj , tempObj , selectedName ) ;
@@ -1347,7 +1365,7 @@ define([
1347
1365
1348
1366
var code = new com_String ( ) ;
1349
1367
code . appendLine ( codeStr ) ;
1350
- code . appendFormat ( "{0}[{1}:{2}].to_json(orient='{3}')" , tempObj , prevLines , lines , 'split' ) ;
1368
+ code . appendFormat ( "{0}.iloc [{1}:{2}].to_json(orient='{3}')" , tempObj , prevLines , lines , 'split' ) ;
1351
1369
1352
1370
this . loading = true ;
1353
1371
vpKernel . execute ( code . toString ( ) ) . then ( function ( resultObj ) {
@@ -1490,7 +1508,7 @@ define([
1490
1508
}
1491
1509
} ) . catch ( function ( resultObj ) {
1492
1510
let { result, type, msg } = resultObj ;
1493
- vpLog . display ( VP_LOG_TYPE . ERROR , result . ename + ': ' + result . evalue , msg ) ;
1511
+ vpLog . display ( VP_LOG_TYPE . ERROR , result . ename + ': ' + result . evalue , msg , code . toString ( ) ) ;
1494
1512
com_util . renderAlertModal ( result . ename + ': ' + result . evalue ) ;
1495
1513
that . loading = false ;
1496
1514
} ) ;
@@ -1579,6 +1597,8 @@ define([
1579
1597
DROP_OUT : 11 ,
1580
1598
1581
1599
ONE_HOT_ENCODING : 6 ,
1600
+ LABEL_ENCODING : 12 ,
1601
+
1582
1602
SET_IDX : 7 ,
1583
1603
RESET_IDX : 8 ,
1584
1604
REPLACE : 9 ,
0 commit comments