nest-join
In [1]:
Copied!
# https://dplyr.tidyverse.org/reference/nest_join.html
%run nb_helpers.py
from datar.data import band_members, band_instruments
from datar.all import *
nb_header(nest_join, book='nest-join')
# https://dplyr.tidyverse.org/reference/nest_join.html
%run nb_helpers.py
from datar.data import band_members, band_instruments
from datar.all import *
nb_header(nest_join, book='nest-join')
Try this notebook on binder.
★ nest_join¶
Nest join two data frames by matching rows.¶
The original API:
https://dplyr.tidyverse.org/reference/join.html
Args:¶
x
: A data frame
y
: A data frame
by
: A list of column names to join by.
If None, use the intersection of the columns of x and y.
copy
: If True, always copy the data.
keep
: If True, keep the grouping variables in the output.
name
: The name of the column to store the nested data frame.
Returns:¶
A data frame
In [2]:
Copied!
nested = band_members >> nest_join(band_instruments)
nested
nested = band_members >> nest_join(band_instruments)
nested
Out[2]:
name | band | _y_joined | |
---|---|---|---|
<object> | <object> | <object> | |
0 | Mick | Stones | <DF 0x1> |
1 | John | Beatles | <DF 1x1> |
2 | Paul | Beatles | <DF 1x1> |
In [3]:
Copied!
nested >> head(2) >> pull(f._y_joined, to='list')
nested >> head(2) >> pull(f._y_joined, to='list')
Out[3]:
[Empty Tibble Columns: [plays] Index: [], plays <object> 0 guitar]