Group by month Danfo.js

581 views Asked by At

My goal is to translate a line of code written in python's pandas to Danfo.js. The python code is the following:

ftest_raw_money_per_month = ftest_raw.groupby(ftest_raw['trans_date'].dt.strftime('%Y-%m'))['tran_amount'].sum().sort_index()

Where the input data ftest_raw is:

       customer_id trans_date  tran_amount  visit_count
13310       CS2884 2011-10-11           73          1.0
13340       CS2884 2011-10-11           50          1.0
16006       CS2884 2011-11-09           68          1.0
16482       CS2884 2011-11-15           79          1.0
19701       CS2884 2011-12-21          101          1.0
21231       CS2884 2012-01-07           45          1.0
37435       CS2884 2012-07-08           58          1.0
51844       CS2884 2012-12-16           73          1.0
57406       CS2884 2013-02-17           87          1.0
64101       CS2884 2013-05-02           39          1.0
70615       CS2884 2013-07-13           70          1.0
73151       CS2884 2013-08-10           57          1.0
81157       CS2884 2013-11-06           88          1.0
83342       CS2884 2013-12-01           42          1.0
84551       CS2884 2013-12-15           39          1.0
86708       CS2884 2014-01-08           56          1.0
89393       CS2884 2014-02-06           63          1.0
96079       CS2884 2014-04-23           70          1.0
97179       CS2884 2014-05-05           98          1.0
99588       CS2884 2014-06-03           40          1.0
124975      CS2884 2015-03-16          103          1.0

And the output data ftest_raw_money_per_month is:

trans_date
2011-10    123
2011-11    147
2011-12    101
2012-01     45
2012-07     58
2012-12     73
2013-02     87
2013-05     39
2013-07     70
2013-08     57
2013-11     88
2013-12     81
2014-01     56
2014-02     63
2014-04     70
2014-05     98
2014-06     40
2015-03    103

My question is the following: Is there any way to do

groupby(ftest_raw['trans_date'].dt.strftime('%Y-%m'))

in Danfo.js? If yes, how? I have read Danfo's documentation but I was unable to find that functionality.

0

There are 0 answers