vDataFrame.cumprod

In [ ]:
vDataFrame.cumprod(column: str, 
                   by: list = [], 
                   order_by = [],
                   name: str = "")

Adds a new vcolumn to the vDataFrame by computing the cumulative product of the input vcolumn.

Parameters

Name Type Optional Description
column
str
❌
Input vcolumn.
by
list
✓
vcolumns used in the partition.
order_by
dict / list
✓
List of the vcolumns to use to sort the data using asc order or dictionary of all the sorting methods. For example, to sort by "column1" ASC and "column2" DESC, write {"column1": "asc", "column2": "desc"}
name
str
✓
Name of the new vcolumn. If empty, a default name will be generated.

Returns

vDataFrame : self

Example

In [146]:
from verticapy.datasets import load_amazon
amazon = load_amazon().last(ts = "date", offset = "6 months")
display(amazon)
6292 element(s) was/were filtered
Abc
state
Varchar(32)
📅
date
Date
123
number
Int
1Paraiba2017-06-010
2Sergipe2017-06-010
3Alagoas2017-07-010
4Sergipe2017-07-010
5Sergipe2017-08-010
6Sergipe2017-09-010
7Sergipe2017-10-010
8Distrito Federal2017-11-010
9Alagoas2017-08-011
10Sergipe2017-11-011
11Alagoas2017-06-012
12Amapa2017-06-012
13Paraiba2017-07-012
14Pernambuco2017-07-012
15Rio2017-06-013
16Amapa2017-07-013
17Espirito Santo2017-07-013
18Roraima2017-07-013
19Paraiba2017-08-013
20Espirito Santo2017-11-013
21Roraima2017-06-014
22Rio2017-07-014
23Alagoas2017-09-014
24Pernambuco2017-06-015
25Alagoas2017-11-0110
26Alagoas2017-10-0114
27Pernambuco2017-08-0120
28Rio2017-08-0121
29Ceara2017-06-0123
30Distrito Federal2017-06-0123
31Ceara2017-07-0126
32Espirito Santo2017-08-0130
33Paraiba2017-09-0130
34Amapa2017-08-0133
35Roraima2017-08-0135
36Espirito Santo2017-06-0137
37Sao Paulo2017-11-0137
38Roraima2017-09-0143
39Rio2017-11-0143
40Distrito Federal2017-07-0144
41Acre2017-06-0145
42Rio2017-09-0148
43Santa Catarina2017-10-0151
44Espirito Santo2017-10-0156
45Espirito Santo2017-09-0158
46Distrito Federal2017-10-0166
47Pernambuco2017-11-0166
48Rio2017-06-0168
49Pernambuco2017-09-0169
50Santa Catarina2017-06-0170
51Rio2017-07-0170
52Rio2017-10-0185
53Rio2017-11-0189
54Amapa2017-09-0195
55Acre2017-11-0198
56Rio2017-10-01101
57Paraiba2017-11-01101
58Rio2017-06-01103
59Goias2017-11-01117
60Amazonas2017-06-01119
61Ceara2017-08-01121
62Distrito Federal2017-09-01122
63Paraiba2017-10-01123
64Mato Grosso2017-11-01133
65Paraiba2017-10-01134
66Minas Gerais2017-11-01136
67Rio2017-11-01137
68Distrito Federal2017-08-01147
69Santa Catarina2017-11-01152
70Roraima2017-10-01156
71Rio2017-08-01164
72Paraiba2017-06-01169
73Bahia2017-11-01174
74Mato Grosso2017-06-01175
75Sao Paulo2017-10-01179
76Rondonia2017-06-01192
77Piau2017-06-01193
78Sao Paulo2017-06-01217
79Rio2017-10-01238
80Pernambuco2017-10-01256
81Paraiba2017-11-01292
82Bahia2017-07-01300
83Roraima2017-11-01327
84Bahia2017-06-01329
85Rio2017-09-01343
86Minas Gerais2017-06-01360
87Rondonia2017-11-01372
88Tocantins2017-11-01434
89Goias2017-06-01442
90Piau2017-11-01449
91Acre2017-07-01457
92Amapa2017-10-01468
93Ceara2017-09-01505
94Amazonas2017-11-01552
95Goias2017-07-01577
96Santa Catarina2017-07-01591
97Minas Gerais2017-07-01610
98Santa Catarina2017-09-01626
99Piau2017-07-01643
100Para2017-06-01679
Rows: 1-100 of 162 | Columns: 3
In [147]:
amazon.cumprod(column = "number",
               by = ["state"],
               order_by = ["date"],
               name = "cumprod_number")
Abc
state
Varchar(32)
📅
date
Date
123
number
Int
123
cumprod_number
Float
1Acre2017-06-014545.0
2Acre2017-07-0145720565.0
3Acre2017-08-01149330703545.0
4Acre2017-09-013429105282455805.0
5Acre2017-10-011508158765943353940.0
6Acre2017-11-01981.55590624486861e+16
7Amazonas2017-06-01119119.0
8Amazonas2017-07-011975235025.0
9Amazonas2017-08-0163161484417900.0
10Amazonas2017-09-0140335986657390699.99
11Amazonas2017-10-0115819464905334696700.0
12Amazonas2017-11-015525.22462774475256e+18
13Bahia2017-06-01329329.0
14Bahia2017-07-0130098700.0000000002
15Bahia2017-08-011018100476600.0
16Bahia2017-09-011791179953590600.0
17Bahia2017-10-014005720714130353002.0
18Bahia2017-11-011741.25404258681422e+17
19Goias2017-06-01442442.0
20Goias2017-07-01577255034.0
21Goias2017-08-011492380510727.999999
22Goias2017-09-0132381232093737264.0
23Goias2017-10-0124012958257063170860.0
24Goias2017-11-011173.46116076390991e+17
25Maranhao2017-06-01885885.0
26Maranhao2017-07-0125212231085.0
27Maranhao2017-08-0138758645454375.00002
28Maranhao2017-09-0114825128168861109375.0
29Maranhao2017-10-0160117.70423024128453e+17
30Maranhao2017-11-0123001.77197295549544e+21
31Piau2017-06-01193193.0
32Piau2017-07-01643124099.0
33Piau2017-08-011572195083628.0
34Piau2017-09-013422667576175016.001
35Piau2017-10-0130042005398829748070.0
36Piau2017-11-014499.00424074556878e+17
37Roraima2017-06-0144.0
38Roraima2017-07-01312.0
39Roraima2017-08-0135420.0
40Roraima2017-09-014318060.0
41Roraima2017-10-011562817360.0
42Roraima2017-11-01327921276720.0
43Sergipe2017-06-0100.0
44Sergipe2017-07-0100.0
45Sergipe2017-08-0100.0
46Sergipe2017-09-0100.0
47Sergipe2017-10-0100.0
48Sergipe2017-11-0110.0
49Tocantins2017-06-0113201320.0
50Tocantins2017-07-0123973164040.0
51Tocantins2017-08-01353611188045440.0
52Tocantins2017-09-0110737120126043889280.0
53Tocantins2017-10-0129693.56654224307274e+17
54Tocantins2017-11-014341.54787933349357e+20
55Alagoas2017-06-0122.0
56Alagoas2017-07-0100.0
57Alagoas2017-08-0110.0
58Alagoas2017-09-0140.0
59Alagoas2017-10-01140.0
60Alagoas2017-11-01100.0
61Amapa2017-06-0122.0
62Amapa2017-07-0136.0
63Amapa2017-08-0133198.0
64Amapa2017-09-019518810.0
65Amapa2017-10-014688803080.00000001
66Amapa2017-11-018587553042640.0
67Ceara2017-06-012323.0
68Ceara2017-07-0126598.0
69Ceara2017-08-0112172358.0
70Ceara2017-09-0150536540790.0
71Ceara2017-10-0194934677209710.0001
72Ceara2017-11-0181228157894284520.0
73Distrito Federal2017-06-012323.0
74Distrito Federal2017-07-01441012.0
75Distrito Federal2017-08-01147148764.0
76Distrito Federal2017-09-0112218149208.0
77Distrito Federal2017-10-01661197847728.0
78Distrito Federal2017-11-0100.0
79Espirito Santo2017-06-013737.0
80Espirito Santo2017-07-013111.0
81Espirito Santo2017-08-01303330.0
82Espirito Santo2017-09-0158193140.0
83Espirito Santo2017-10-015610815840.0
84Espirito Santo2017-11-01332447520.0
85Mato Grosso2017-06-01175175.0
86Mato Grosso2017-06-012041357175.0
87Mato Grosso2017-07-011050375033750.0
88Mato Grosso2017-07-0127901046344162500.0
89Mato Grosso2017-08-0114881556960113800000.0
90Mato Grosso2017-08-0162299.69830454886018e+18
91Mato Grosso2017-09-01239452.32225902422457e+23
92Mato Grosso2017-09-0129846.92962092828614e+26
93Mato Grosso2017-10-0148003.32621804557735e+30
94Mato Grosso2017-10-016852.27845936122046e+33
95Mato Grosso2017-11-011333.03035095042324e+35
96Mato Grosso2017-11-018132.46367532269408e+38
97Minas Gerais2017-06-01360360.0
98Minas Gerais2017-07-01610219600.0
99Minas Gerais2017-08-012142470383199.999999
100Minas Gerais2017-09-0146972209389890400.0
Out[147]:
Rows: 1-100 of 162 | Columns: 4

See Also

vDataFrame.rolling Computes a customized moving window.