@@ -776,7 +776,7 @@ export class DataFrame extends Ndframe {
776776 let col_names = numeric_df . column_names
777777 let index = [ 'count' , 'mean' , 'std' , 'min' , 'median' , 'max' , 'variance' ]
778778
779- let stats_arr = [ ]
779+ let stats_arr = { }
780780 col_names . forEach ( name => {
781781 let col_series = numeric_df [ name ]
782782 let count = col_series . count ( )
@@ -788,9 +788,7 @@ export class DataFrame extends Ndframe {
788788 let variance = col_series . var ( )
789789
790790 let _stats = [ count , mean , std , min , median , max , variance ]
791- let col_obj = { }
792- col_obj [ name ] = _stats
793- stats_arr . push ( col_obj )
791+ stats_arr [ name ] = _stats
794792
795793 } )
796794 let df = new DataFrame ( stats_arr , { "index" : index } )
@@ -803,42 +801,36 @@ export class DataFrame extends Ndframe {
803801 * @param {include } scalar or array-like. A selection of dtypes or strings to be included. At least one of these parameters must be supplied.
804802 * @returns {DataFrame, Series } The subset of the frame including the dtypes.
805803 */
806- select_dtypes ( include = [ "" ] ) {
804+ select_dtypes ( include ) {
807805 let dtypes = this . dtypes
808- // let dtype_index = [...Array( this.dtypes.length - 1).keys()]
809- let col_vals = [ ]
806+ let col_names = this . column_names
807+ let col_vals = { }
810808 let original_col_vals = this . col_data
811- const __supported_dtypes = [ 'float32' , "int32" , 'string' , 'datetime ' ]
809+ const __supported_dtypes = [ 'float32' , "int32" , 'string' , 'boolean ' ]
812810
813- if ( include == [ "" ] || include == [ ] ) {
811+ if ( include == undefined ) {
814812 //return all
815813 let df = this . copy ( )
816814 return df
817815 } else {
818816 //check if the right types are included
819817 include . forEach ( type => {
820818 if ( ! __supported_dtypes . includes ( type ) ) {
821- throw Error ( `Dtype Error: dtype ${ type } not found in dtypes ` )
819+ throw Error ( `Dtype Error: dtype ${ type } not supported. ` )
822820 }
823- dtypes . map ( ( dtype , i ) => {
824- if ( dtype == type ) {
825- let _obj = { }
826- _obj [ this . column_names [ i ] ] = original_col_vals [ i ]
827- col_vals . push ( _obj )
828- }
829- } )
821+ } )
822+
823+
824+ dtypes . forEach ( ( dtype , i ) => {
825+ if ( include . includes ( dtype ) ) {
826+ console . log ( dtype ) ;
827+ col_vals [ col_names [ i ] ] = original_col_vals [ i ]
828+ }
829+ } )
830+ let df = new DataFrame ( col_vals )
831+ df . print ( )
832+ return df
830833
831- } ) ;
832- if ( col_vals . length == 1 ) {
833- let _key = Object . keys ( col_vals [ 0 ] ) [ 0 ]
834- let data = col_vals [ 0 ] [ _key ]
835- let column_name = [ _key ]
836- let sf = new Series ( data , { columns : column_name , index : this . index } )
837- return sf
838- } else {
839- let df = new DataFrame ( col_vals , { index : this . index } )
840- return df
841- }
842834 }
843835
844836 }
@@ -1209,6 +1201,7 @@ export class DataFrame extends Ndframe {
12091201 }
12101202 } )
12111203
1204+
12121205 if ( kwargs [ 'columns' ] . length != kwargs [ 'values' ] . length ) {
12131206 throw Error ( `Lenght Error: The lenght of the columns names must be equal to the lenght of the values,
12141207 got column of length ${ kwargs [ 'columns' ] . length } but values of length ${ kwargs [ 'values' ] . length } ` )
@@ -1231,38 +1224,11 @@ export class DataFrame extends Ndframe {
12311224
12321225 } )
12331226
1234- let final_data = [ ]
1227+ let final_data = { }
12351228 new_col_data . map ( ( col , i ) => {
1236- let col_obj = { }
1237- col_obj [ this . column_names [ i ] ] = col
1238- final_data . push ( col_obj )
1229+ final_data [ this . column_names [ i ] ] = col
12391230 } )
1240- // let fil_idx = 0
1241- // this.column_names.map((col, idx) => {
1242- // let _obj = {}
1243- // if (kwargs['columns'].includes(col)) {
1244- // console.log(fil_idx);
1245- // console.log(col);
1246- // console.log(kwargs['values'][fil_idx]);
1247- // let temp_col_data = this.col_data[idx] //retreive the column data
1248- // let __temp = []
1249- // temp_col_data.map(val => { //fill the column
1250- // if (isNaN(val) && typeof val != "string") {
1251- // __temp.push(kwargs['values'][fil_idx])
1252-
1253- // } else {
1254- // __temp.push(val)
1255- // }
1256- // })
1257- // fil_idx += 1
1258- // _obj[col] = __temp
1259- // new_col_data_obj.push(_obj)
1260- // } else {
1261- // _obj[col] = this.col_data[idx]
1262- // new_col_data_obj.push(_obj)
1263- // }
1264-
1265- // })
1231+
12661232 return new DataFrame ( final_data , { index : this . index } )
12671233
12681234 } else {
@@ -1663,9 +1629,8 @@ export class DataFrame extends Ndframe {
16631629 } )
16641630
16651631 if ( utils . __key_in_object ( kwargs , "replace" ) && utils . __key_in_object ( kwargs , "with" ) ) {
1666- let new_col_data_obj = [ ]
1632+ let new_col_data_obj = { }
16671633 this . column_names . map ( ( col , idx ) => {
1668- let _obj = { }
16691634 if ( kwargs [ 'in' ] . includes ( col ) ) {
16701635 let temp_col_data = this . col_data [ idx ] //retreive the column data
16711636 let __temp = [ ]
@@ -1676,11 +1641,9 @@ export class DataFrame extends Ndframe {
16761641 __temp . push ( val )
16771642 }
16781643 } )
1679- _obj [ col ] = __temp
1680- new_col_data_obj . push ( _obj )
1644+ new_col_data_obj [ col ] = __temp
16811645 } else {
1682- _obj [ col ] = this . col_data [ idx ]
1683- new_col_data_obj . push ( _obj )
1646+ new_col_data_obj [ col ] = this . col_data [ idx ]
16841647 }
16851648 } )
16861649 return new DataFrame ( new_col_data_obj , { columns : this . column_names , index : this . index } )
@@ -1900,7 +1863,7 @@ export class DataFrame extends Ndframe {
19001863 return plt
19011864 }
19021865
1903-
1866+
19041867
19051868 /**
19061869 * Returns the Tensorflow tensor backing the DataFrame Object
@@ -1963,11 +1926,9 @@ export class DataFrame extends Ndframe {
19631926 break ;
19641927 }
19651928
1966- let new_col_obj = [ ]
1929+ let new_col_obj = { }
19671930 this . column_names . forEach ( ( cname , i ) => {
1968- let _obj = { }
1969- _obj [ cname ] = col_values [ i ]
1970- new_col_obj . push ( _obj )
1931+ new_col_obj [ cname ] = col_values [ i ]
19711932 } )
19721933
19731934 let df = new DataFrame ( new_col_obj , { dtypes : new_types , index : this . index } )
0 commit comments