cumall
In [1]:
Copied!
# https://dplyr.tidyverse.org/reference/cumall.html
%run nb_helpers.py
import numpy
from datar.all import *
nb_header(cummean, cumsum, cumall, cumany, cumany, book='cumall')
# https://dplyr.tidyverse.org/reference/cumall.html
%run nb_helpers.py
import numpy
from datar.all import *
nb_header(cummean, cumsum, cumall, cumany, cumany, book='cumall')
Try this notebook on binder.
★ cummean¶
Cumulative mean¶
The original API:
https://dplyr.tidyverse.org/reference/cumall.html
Args:¶
x
: A numeric vector
na_rm
: If True
, remove missing values before computing.
Returns:¶
An array of cumulative means
★ cumsum¶
★ cumall¶
Get cumulative bool. All cases after first False¶
The original API:
https://dplyr.tidyverse.org/reference/cumall.html
Args:¶
x
: A logical vector
Returns:¶
An array of cumulative conjunctions
★ cumany¶
Get cumulative bool. All cases after first True¶
The original API:
https://dplyr.tidyverse.org/reference/cumany.html
Args:¶
x
: A logical vector
Returns:¶
An array of cumulative disjunctions
★ cumany¶
Get cumulative bool. All cases after first True¶
The original API:
https://dplyr.tidyverse.org/reference/cumany.html
Args:¶
x
: A logical vector
Returns:¶
An array of cumulative disjunctions
In [2]:
Copied!
x = [1, 3, 5, 2, 2]
cummean(x)
x = [1, 3, 5, 2, 2]
cummean(x)
Out[2]:
0 1.00 1 2.00 2 3.00 3 2.75 4 2.60 dtype: float64
In [3]:
Copied!
cumsum(x) / seq_along(x)
cumsum(x) / seq_along(x)
Out[3]:
array([1. , 2. , 3. , 2.75, 2.6 ])
In [4]:
Copied!
cumall(numpy.array(x) < 5)
cumall(numpy.array(x) < 5)
Out[4]:
0 True 1 True 2 False 3 False 4 False dtype: bool
In [5]:
Copied!
cumany(numpy.array(x) == 3)
cumany(numpy.array(x) == 3)
Out[5]:
0 False 1 True 2 True 3 True 4 True dtype: bool
In [6]:
Copied!
df = tibble(
date = as_date([f"2020-01-0{i+1}" for i in range(7)]),
balance = c(100, 50, 25, -25, -50, 30, 120)
)
df >> filter(cumany(f.balance < 0))
df = tibble(
date = as_date([f"2020-01-0{i+1}" for i in range(7)]),
balance = c(100, 50, 25, -25, -50, 30, 120)
)
df >> filter(cumany(f.balance < 0))
Out[6]:
date | balance | |
---|---|---|
<object> | <int64> | |
3 | 2020-01-04 | -25 |
4 | 2020-01-05 | -50 |
5 | 2020-01-06 | 30 |
6 | 2020-01-07 | 120 |
In [7]:
Copied!
df >> filter(cumall(~(f.balance < 0)))
df >> filter(cumall(~(f.balance < 0)))
Out[7]:
date | balance | |
---|---|---|
<object> | <int64> | |
0 | 2020-01-01 | 100 |
1 | 2020-01-02 | 50 |
2 | 2020-01-03 | 25 |