vDataFrame.cumsum

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

Adds a new vcolumn to the vDataFrame by computing the cumulative sum 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 [148]:
from verticapy.datasets import load_amazon
amazon = load_amazon()
display(amazon)
Abc
state
Varchar(32)
📅
date
Date
123
number
Int
1Acre1998-01-010
2Alagoas1998-01-010
3Amapa1998-01-010
4Amazonas1998-01-010
5Bahia1998-01-010
6Ceara1998-01-010
7Distrito Federal1998-01-010
8Espirito Santo1998-01-010
9Goias1998-01-010
10Maranhao1998-01-010
11Mato Grosso1998-01-010
12Mato Grosso1998-01-010
13Minas Gerais1998-01-010
14Para1998-01-010
15Paraiba1998-01-010
16Paraiba1998-01-010
17Pernambuco1998-01-010
18Piau1998-01-010
19Rio1998-01-010
20Rio1998-01-010
21Rio1998-01-010
22Rondonia1998-01-010
23Roraima1998-01-010
24Santa Catarina1998-01-010
25Sao Paulo1998-01-010
26Sergipe1998-01-010
27Tocantins1998-01-010
28Acre1998-02-010
29Alagoas1998-02-010
30Amapa1998-02-010
31Amazonas1998-02-010
32Bahia1998-02-010
33Ceara1998-02-010
34Distrito Federal1998-02-010
35Espirito Santo1998-02-010
36Goias1998-02-010
37Maranhao1998-02-010
38Mato Grosso1998-02-010
39Mato Grosso1998-02-010
40Minas Gerais1998-02-010
41Para1998-02-010
42Paraiba1998-02-010
43Paraiba1998-02-010
44Pernambuco1998-02-010
45Piau1998-02-010
46Rio1998-02-010
47Rio1998-02-010
48Rio1998-02-010
49Rondonia1998-02-010
50Roraima1998-02-010
51Santa Catarina1998-02-010
52Sao Paulo1998-02-010
53Sergipe1998-02-010
54Tocantins1998-02-010
55Acre1998-03-010
56Alagoas1998-03-010
57Amapa1998-03-010
58Amazonas1998-03-010
59Bahia1998-03-010
60Ceara1998-03-010
61Distrito Federal1998-03-010
62Espirito Santo1998-03-010
63Goias1998-03-010
64Maranhao1998-03-010
65Mato Grosso1998-03-010
66Mato Grosso1998-03-010
67Minas Gerais1998-03-010
68Para1998-03-010
69Paraiba1998-03-010
70Paraiba1998-03-010
71Pernambuco1998-03-010
72Piau1998-03-010
73Rio1998-03-010
74Rio1998-03-010
75Rio1998-03-010
76Rondonia1998-03-010
77Roraima1998-03-010
78Santa Catarina1998-03-010
79Sao Paulo1998-03-010
80Sergipe1998-03-010
81Tocantins1998-03-010
82Acre1998-04-010
83Alagoas1998-04-010
84Amapa1998-04-010
85Amazonas1998-04-010
86Bahia1998-04-010
87Ceara1998-04-010
88Distrito Federal1998-04-010
89Espirito Santo1998-04-010
90Goias1998-04-010
91Maranhao1998-04-010
92Mato Grosso1998-04-010
93Mato Grosso1998-04-010
94Minas Gerais1998-04-010
95Para1998-04-010
96Paraiba1998-04-010
97Paraiba1998-04-010
98Pernambuco1998-04-010
99Piau1998-04-010
100Rio1998-04-010
Rows: 1-100 of 6454 | Columns: 3
In [149]:
amazon.cumsum(column = "number",
              by = ["state"],
              order_by = ["date"],
              name = "cumsum_number")
Abc
state
Varchar(32)
📅
date
Date
123
number
Int
123
cumsum_number
Integer
1Acre1998-01-0100
2Acre1998-02-0100
3Acre1998-03-0100
4Acre1998-04-0100
5Acre1998-05-0100
6Acre1998-06-0133
7Acre1998-07-013740
8Acre1998-08-01130170
9Acre1998-09-01509679
10Acre1998-10-0144723
11Acre1998-11-010723
12Acre1998-12-017730
13Acre1999-01-010730
14Acre1999-02-010730
15Acre1999-03-010730
16Acre1999-04-010730
17Acre1999-05-010730
18Acre1999-06-010730
19Acre1999-07-011731
20Acre1999-08-0163794
21Acre1999-09-012091003
22Acre1999-10-01601063
23Acre1999-11-0101063
24Acre1999-12-0101063
25Acre2000-01-0101063
26Acre2000-02-0101063
27Acre2000-03-01111074
28Acre2000-04-0111075
29Acre2000-05-0111076
30Acre2000-06-0111077
31Acre2000-07-0111078
32Acre2000-08-011361214
33Acre2000-09-012651479
34Acre2000-10-01181497
35Acre2000-11-0101497
36Acre2000-12-0101497
37Acre2001-01-0101497
38Acre2001-02-0101497
39Acre2001-03-0101497
40Acre2001-04-0101497
41Acre2001-05-0101497
42Acre2001-06-0111498
43Acre2001-07-0131501
44Acre2001-08-013961897
45Acre2001-09-012902187
46Acre2001-10-011372324
47Acre2001-11-0112325
48Acre2001-12-0102325
49Acre2002-01-0102325
50Acre2002-02-0112326
51Acre2002-03-0102326
52Acre2002-04-0102326
53Acre2002-05-0102326
54Acre2002-06-0102326
55Acre2002-07-01392365
56Acre2002-08-017283093
57Acre2002-09-0119495042
58Acre2002-10-016875729
59Acre2002-11-01865815
60Acre2002-12-0115816
61Acre2003-01-01105826
62Acre2003-02-0105826
63Acre2003-03-0105826
64Acre2003-04-0115827
65Acre2003-05-0165833
66Acre2003-06-0105833
67Acre2003-07-011686001
68Acre2003-08-0119767977
69Acre2003-09-01394211919
70Acre2003-10-0174012659
71Acre2003-11-011512674
72Acre2003-12-01112675
73Acre2004-01-01012675
74Acre2004-02-01312678
75Acre2004-03-01012678
76Acre2004-04-01212680
77Acre2004-05-01712687
78Acre2004-06-01512692
79Acre2004-07-014212734
80Acre2004-08-0164513379
81Acre2004-09-01197815357
82Acre2004-10-0146115818
83Acre2004-11-011015828
84Acre2004-12-01715835
85Acre2005-01-011215847
86Acre2005-02-01015847
87Acre2005-03-01315850
88Acre2005-04-01115851
89Acre2005-05-01215853
90Acre2005-06-012715880
91Acre2005-07-0136816248
92Acre2005-08-01419820446
93Acre2005-09-01425324699
94Acre2005-10-0154725246
95Acre2005-11-011425260
96Acre2005-12-01225262
97Acre2006-01-01425266
98Acre2006-02-01025266
99Acre2006-03-01025266
100Acre2006-04-01025266
Out[149]:
Rows: 1-100 of 6454 | Columns: 4
In [25]:
amazon["cumsum_number"].plot(ts = "date", by = "state")

See Also

vDataFrame.rolling Computes a customized moving window.