@@ -181,4 +181,57 @@ describe("groupby", function () {
181181 assert . deepEqual ( group_df . col ( [ "B" , "C" ] ) . mean ( ) . values , new_data ) ;
182182 } ) ;
183183
184+ it ( "printing multiindex table, example with cumsum operation for dataframe group by one column" , function ( ) {
185+ let data = [ { 'A' : [ 'foo' , 'bar' , 'foo' , 'bar' ,
186+ 'foo' , 'bar' , 'foo' , 'foo' ] } ,
187+ { 'B' : [ 'one' , 'one' , 'two' , 'three' ,
188+ 'two' , 'two' , 'one' , 'three' ] } ,
189+ { 'C' : [ 1 , 3 , 2 , 4 , 5 , 2 , 6 , 7 ] } ,
190+ { 'D' : [ 3 , 2 , 4 , 1 , 5 , 6 , 7 , 8 ] }
191+ ]
192+
193+ let df = new DataFrame ( data )
194+
195+
196+ let grp = df . groupby ( [ "A" ] )
197+ let rslt = [
198+ [ 'foo' , 1 ] ,
199+ [ 'foo' , 3 ] ,
200+ [ 'foo' , 8 ] ,
201+ [ 'foo' , 14 ] ,
202+ [ 'foo' , 21 ] ,
203+ [ 'bar' , 3 ] ,
204+ [ 'bar' , 7 ] ,
205+ [ 'bar' , 9 ]
206+ ]
207+ assert . deepEqual ( grp . col ( [ "C" ] ) . cumsum ( ) . values , rslt ) ;
208+
209+ } )
210+ it ( "printing multiindex table, example with cumsum operation for dataframe group by one column" , function ( ) {
211+ let data = [ { 'A' : [ 'foo' , 'bar' , 'foo' , 'bar' ,
212+ 'foo' , 'bar' , 'foo' , 'foo' ] } ,
213+ { 'B' : [ 'one' , 'one' , 'two' , 'three' ,
214+ 'two' , 'two' , 'one' , 'three' ] } ,
215+ { 'C' : [ 1 , 3 , 2 , 4 , 5 , 2 , 6 , 7 ] } ,
216+ { 'D' : [ 3 , 2 , 4 , 1 , 5 , 6 , 7 , 8 ] }
217+ ]
218+
219+ let df = new DataFrame ( data )
220+
221+
222+ let grp = df . groupby ( [ "A" , "B" ] )
223+ let rslt = [
224+ [ 'foo' , 'one' , 1 , 3 ] ,
225+ [ 'foo' , 'one' , 7 , 10 ] ,
226+ [ 'foo' , 'two' , 2 , 4 ] ,
227+ [ 'foo' , 'two' , 7 , 9 ] ,
228+ [ 'foo' , 'three' , 7 , 8 ] ,
229+ [ 'bar' , 'one' , 3 , 2 ] ,
230+ [ 'bar' , 'two' , 2 , 6 ] ,
231+ [ 'bar' , 'three' , 4 , 1 ]
232+ ]
233+ assert . deepEqual ( grp . col ( [ "C" , "D" ] ) . cumsum ( ) . values , rslt )
234+
235+ } )
236+
184237} ) ;
0 commit comments