expand_grid
In [1]:
Copied!
# https://tidyr.tidyverse.org/reference/expand_grid.html
%run nb_helpers.py
from datar.all import *
nb_header(expand_grid)
# https://tidyr.tidyverse.org/reference/expand_grid.html
%run nb_helpers.py
from datar.all import *
nb_header(expand_grid)
In [2]:
Copied!
expand_grid(x=seq(1,3), y=seq(1,2))
expand_grid(x=seq(1,3), y=seq(1,2))
Out[2]:
x | y | |
---|---|---|
<int64> | <int64> | |
0 | 1 | 1 |
1 | 1 | 2 |
2 | 2 | 1 |
3 | 2 | 2 |
4 | 3 | 1 |
5 | 3 | 2 |
In [3]:
Copied!
expand_grid(l1=letters, l2=LETTERS)
expand_grid(l1=letters, l2=LETTERS)
Out[3]:
l1 | l2 | |
---|---|---|
<object> | <object> | |
0 | a | A |
1 | a | B |
2 | a | C |
3 | a | D |
... | ... | ... |
4 | a | E |
671 | z | V |
672 | z | W |
673 | z | X |
674 | z | Y |
675 | z | Z |
676 rows × 2 columns
In [4]:
Copied!
expand_grid(df=tibble(x=[1,2], y=c(2, 1)), z=[1,2,3])
expand_grid(df=tibble(x=[1,2], y=c(2, 1)), z=[1,2,3])
Out[4]:
df$x | df$y | z | |
---|---|---|---|
<int64> | <int64> | <int64> | |
0 | 1 | 2 | 1 |
1 | 1 | 2 | 2 |
2 | 1 | 2 | 3 |
3 | 2 | 1 | 1 |
4 | 2 | 1 | 2 |
5 | 2 | 1 | 3 |
In [5]:
Copied!
expand_grid(x1=tibble(a=[1,2], b=[3,4]), x2=tibble(a=[5,6], b=[7,8]))
expand_grid(x1=tibble(a=[1,2], b=[3,4]), x2=tibble(a=[5,6], b=[7,8]))
Out[5]:
x1$a | x1$b | x2$a | x2$b | |
---|---|---|---|---|
<int64> | <int64> | <int64> | <int64> | |
0 | 1 | 3 | 5 | 7 |
1 | 1 | 3 | 6 | 8 |
2 | 2 | 4 | 5 | 7 |
3 | 2 | 4 | 6 | 8 |