@@ -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
@@ -716,6 +719,12 @@ define([
716719$ ( document ) . on ( 'change' , this . _wrapSelector ( '#vp_gbDisplay' ) , function ( event ) {
717720var colList = event . dataList ;
718721that . state . display = colList ;
722+
723+ if ( colList && colList . length == 1 ) {
724+ $ ( that . _wrapSelector ( '#vp_gbToFrame' ) ) . parent ( ) . show ( ) ;
725+ } else {
726+ $ ( that . _wrapSelector ( '#vp_gbToFrame' ) ) . parent ( ) . hide ( ) ;
727+ }
719728} ) ;
720729
721730// display select button event
@@ -756,6 +765,11 @@ define([
756765$ ( document ) . on ( 'change' , this . _wrapSelector ( '#vp_gbAllocateTo' ) , function ( ) {
757766that . state . allocateTo = $ ( this ) . val ( ) ;
758767} ) ;
768+
769+ // to dataframe event
770+ $ ( document ) . on ( 'change' , this . _wrapSelector ( '#vp_gbToFrame' ) , function ( ) {
771+ that . state . toFrame = $ ( this ) . prop ( 'checked' ) == true ;
772+ } ) ;
759773
760774// reset index checkbox event
761775$ ( document ) . on ( 'change' , this . _wrapSelector ( '#vp_gbResetIndex' ) , function ( ) {
@@ -1009,9 +1023,13 @@ define([
10091023var code = new sb . StringBuilder ( ) ;
10101024var {
10111025 variable, groupby, useGrouper, grouperNumber, grouperPeriod,
1012- display, method, advanced, allocateTo, resetIndex
1026+ display, method, advanced, allocateTo, toFrame , resetIndex
10131027} = this . state ;
10141028
1029+ if ( ! variable || variable == '' ) {
1030+ return '' ;
1031+ }
1032+
10151033// mapping colList states
10161034groupby = groupby . map ( col => col . code ) ;
10171035display = display . map ( col => col . code ) ;
@@ -1048,13 +1066,13 @@ define([
10481066//====================================================================
10491067var colStr = '' ;
10501068if ( display ) {
1051- if ( display . length == 1 ) {
1052- // for 1 column
1053- colStr = '[' + display . join ( '' ) + ']' ;
1054- } else if ( display . length > 1 ) {
1069+ if ( toFrame || display . length > 1 ) {
10551070// over 2 columns
10561071colStr = '[[' + display . join ( ',' ) + ']]' ;
1057- }
1072+ } else if ( display . length == 1 ) {
1073+ // for 1 column
1074+ colStr = '[' + display . join ( '' ) + ']' ;
1075+ }
10581076}
10591077
10601078//====================================================================
@@ -1172,21 +1190,24 @@ define([
11721190//================================================================
11731191// Method code generation
11741192//================================================================
1175- methodStr . appendFormat ( '{0}()' , method ) ;
1193+ if ( method != '' ) {
1194+ methodStr . appendFormat ( '{0}()' , method ) ;
1195+ }
11761196}
11771197
1178- // when using as_index option with Grouper, use .reset_index()
1179- if ( useGrouper && resetIndex ) {
1180- methodStr . append ( '.reset_index()' ) ;
1198+ if ( method != '' ) {
1199+ // when using as_index option with Grouper, use .reset_index()
1200+ if ( useGrouper && resetIndex ) {
1201+ methodStr . append ( '.reset_index()' ) ;
1202+ }
1203+ // display columns
1204+ code . appendFormat ( '{0}.{1}' , colStr , methodStr . toString ( ) ) ;
11811205}
1182- // display columns
1183- code . appendFormat ( '{0}.{1}' , colStr , methodStr . toString ( ) ) ;
1184-
1206+
11851207if ( allocateTo && allocateTo != '' ) {
11861208code . appendLine ( ) ;
11871209code . append ( allocateTo ) ;
11881210}
1189-
11901211return code . toString ( ) ;
11911212}
11921213