filter-joins
In [1]:
Copied!
# https://dplyr.tidyverse.org/reference/filter-joins.html
%run nb_helpers.py
from datar.data import band_members, band_instruments
from datar.all import *
nb_header(semi_join, anti_join, book='filter-joins')
# https://dplyr.tidyverse.org/reference/filter-joins.html
%run nb_helpers.py
from datar.data import band_members, band_instruments
from datar.all import *
nb_header(semi_join, anti_join, book='filter-joins')
Try this notebook on binder.
★ semi_join¶
Semi 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.
Returns:¶
A data frame
★ anti_join¶
Anti 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.
Returns:¶
A data frame
In [2]:
Copied!
band_members
band_members
Out[2]:
name | band | |
---|---|---|
<object> | <object> | |
0 | Mick | Stones |
1 | John | Beatles |
2 | Paul | Beatles |
In [3]:
Copied!
band_instruments
band_instruments
Out[3]:
name | plays | |
---|---|---|
<object> | <object> | |
0 | John | guitar |
1 | Paul | bass |
2 | Keith | guitar |
In [4]:
Copied!
band_members >> semi_join(band_instruments)
band_members >> semi_join(band_instruments)
Out[4]:
name | band | |
---|---|---|
<object> | <object> | |
1 | John | Beatles |
2 | Paul | Beatles |
In [5]:
Copied!
band_members >> anti_join(band_instruments, by={'name': 'name'})
band_members >> anti_join(band_instruments, by={'name': 'name'})
Out[5]:
name | band | |
---|---|---|
<object> | <object> | |
0 | Mick | Stones |