@@ -102,6 +102,7 @@ define([
102102]
103103
104104this . methodList = [
105+ { label :'None' , value :'' } ,
105106{ label :'count' , value :'count' } ,
106107{ label :'first' , value :'first' } ,
107108{ label :'last' , value :'last' } ,
@@ -134,13 +135,14 @@ define([
134135_loadState ( state ) {
135136var {
136137 variable, groupby, useGrouper, grouperNumber, grouperPeriod,
137- display, method, advanced, allocateTo, resetIndex,
138+ display, method, advanced, allocateTo, toFrame , resetIndex,
138139 advPageDom, advColList, advNamingList
139140} = state ;
140141
141142$ ( this . _wrapSelector ( '#vp_gbVariable' ) ) . val ( variable ) ;
142143$ ( this . _wrapSelector ( '#vp_gbBy' ) ) . val ( groupby . map ( col => col . code ) . join ( ',' ) ) ;
143144$ ( this . _wrapSelector ( '#vp_gbBy' ) ) . data ( 'list' , groupby ) ;
145+ $ ( this . _wrapSelector ( '#vp_gbResetIndex' ) ) . val ( resetIndex ?'yes' :'no' ) ;
144146if ( useGrouper ) {
145147$ ( this . _wrapSelector ( '#vp_gbByGrouper' ) ) . removeAttr ( 'disabled' ) ;
146148$ ( this . _wrapSelector ( '#vp_gbByGrouper' ) ) . prop ( 'checked' , useGrouper ) ;
@@ -157,7 +159,7 @@ define([
157159$ ( this . _wrapSelector ( '#vp_gbAdvanced' ) ) . trigger ( 'change' ) ;
158160}
159161$ ( this . _wrapSelector ( '#vp_gbAllocateTo' ) ) . val ( allocateTo ) ;
160- $ ( this . _wrapSelector ( '#vp_gbResetIndex ' ) ) . val ( resetIndex ? 'yes' : 'no' ) ;
162+ $ ( this . _wrapSelector ( '#vp_gbToFrame ' ) ) . val ( toFrame ) ;
161163
162164$ ( this . _wrapSelector ( '.vp-gb-adv-box' ) ) . html ( advPageDom ) ;
163165
@@ -358,6 +360,7 @@ define([
358360page . appendLine ( '<div>' ) ;
359361page . appendFormatLine ( '<label for="{0}" class="{1}">{2}</label>' , 'vp_gbAllocateTo' , 'wp80' , 'Allocate to' ) ;
360362page . appendFormatLine ( '<input type="text" id="{0}" placeholder="{1}"/>' , 'vp_gbAllocateTo' , 'New variable name' ) ;
363+ page . appendFormatLine ( '<label style="display:none;"><input type="checkbox" id="{0}"/><span>{1}</span></label>' , 'vp_gbToFrame' , 'To DataFrame' ) ;
361364page . appendLine ( '</div>' ) ;
362365
363366page . appendLine ( '</div>' ) ; // end of df-box
@@ -618,6 +621,7 @@ define([
618621$ ( document ) . off ( 'change' , this . _wrapSelector ( '#vp_gbMethodSelect' ) ) ;
619622$ ( document ) . off ( 'change' , this . _wrapSelector ( '#vp_gbAdvanced' ) ) ;
620623$ ( document ) . off ( 'change' , this . _wrapSelector ( '#vp_gbAllocateTo' ) ) ;
624+ $ ( document ) . off ( 'change' , this . _wrapSelector ( '#vp_gbToFrame' ) ) ;
621625$ ( document ) . off ( 'change' , this . _wrapSelector ( '#vp_gbResetIndex' ) ) ;
622626
623627$ ( document ) . off ( 'click' , this . _wrapSelector ( '#vp_gbAdvAdd' ) ) ;
@@ -716,6 +720,12 @@ define([
716720$ ( document ) . on ( 'change' , this . _wrapSelector ( '#vp_gbDisplay' ) , function ( event ) {
717721var colList = event . dataList ;
718722that . state . display = colList ;
723+
724+ if ( colList && colList . length == 1 ) {
725+ $ ( that . _wrapSelector ( '#vp_gbToFrame' ) ) . parent ( ) . show ( ) ;
726+ } else {
727+ $ ( that . _wrapSelector ( '#vp_gbToFrame' ) ) . parent ( ) . hide ( ) ;
728+ }
719729} ) ;
720730
721731// display select button event
@@ -756,6 +766,11 @@ define([
756766$ ( document ) . on ( 'change' , this . _wrapSelector ( '#vp_gbAllocateTo' ) , function ( ) {
757767that . state . allocateTo = $ ( this ) . val ( ) ;
758768} ) ;
769+
770+ // to dataframe event
771+ $ ( document ) . on ( 'change' , this . _wrapSelector ( '#vp_gbToFrame' ) , function ( ) {
772+ that . state . toFrame = $ ( this ) . prop ( 'checked' ) == true ;
773+ } ) ;
759774
760775// reset index checkbox event
761776$ ( document ) . on ( 'change' , this . _wrapSelector ( '#vp_gbResetIndex' ) , function ( ) {
@@ -1009,9 +1024,13 @@ define([
10091024var code = new sb . StringBuilder ( ) ;
10101025var {
10111026 variable, groupby, useGrouper, grouperNumber, grouperPeriod,
1012- display, method, advanced, allocateTo, resetIndex
1027+ display, method, advanced, allocateTo, toFrame , resetIndex
10131028} = this . state ;
10141029
1030+ if ( ! variable || variable == '' ) {
1031+ return '' ;
1032+ }
1033+
10151034// mapping colList states
10161035groupby = groupby . map ( col => col . code ) ;
10171036display = display . map ( col => col . code ) ;
@@ -1048,13 +1067,13 @@ define([
10481067//====================================================================
10491068var colStr = '' ;
10501069if ( display ) {
1051- if ( display . length == 1 ) {
1052- // for 1 column
1053- colStr = '[' + display . join ( '' ) + ']' ;
1054- } else if ( display . length > 1 ) {
1070+ if ( toFrame || display . length > 1 ) {
10551071// over 2 columns
10561072colStr = '[[' + display . join ( ',' ) + ']]' ;
1057- }
1073+ } else if ( display . length == 1 ) {
1074+ // for 1 column
1075+ colStr = '[' + display . join ( '' ) + ']' ;
1076+ }
10581077}
10591078
10601079//====================================================================
@@ -1172,21 +1191,24 @@ define([
11721191//================================================================
11731192// Method code generation
11741193//================================================================
1175- methodStr . appendFormat ( '{0}()' , method ) ;
1194+ if ( method != '' ) {
1195+ methodStr . appendFormat ( '{0}()' , method ) ;
1196+ }
11761197}
11771198
1178- // when using as_index option with Grouper, use .reset_index()
1179- if ( useGrouper && resetIndex ) {
1180- methodStr . append ( '.reset_index()' ) ;
1199+ if ( method != '' ) {
1200+ // when using as_index option with Grouper, use .reset_index()
1201+ if ( useGrouper && resetIndex ) {
1202+ methodStr . append ( '.reset_index()' ) ;
1203+ }
1204+ // display columns
1205+ code . appendFormat ( '{0}.{1}' , colStr , methodStr . toString ( ) ) ;
11811206}
1182- // display columns
1183- code . appendFormat ( '{0}.{1}' , colStr , methodStr . toString ( ) ) ;
1184-
1207+
11851208if ( allocateTo && allocateTo != '' ) {
11861209code . appendLine ( ) ;
11871210code . append ( allocateTo ) ;
11881211}
1189-
11901212return code . toString ( ) ;
11911213}
11921214