这是使用python数据结构的代码:
from datatable import dt, f, by, join
DT = dt.Frame(x = ["b"]*3 + ["a"]*3 + ["c"]*3,
y = [1, 3, 6] * 3,
v = range(1, 10))
X = dt.Frame({"x":('c','b'),
"v":(8,7),
"foo":(4,2)})
X.key="x" # key the ``x`` column
merger = DT[:, :, join(X)]
merger
x y v v.0 foo
0 b 1 1 7 2
1 b 3 2 7 2
2 b 6 3 7 2
3 a 1 4 NA NA
4 a 3 5 NA NA
5 a 6 6 NA NA
6 c 1 7 8 4
7 c 3 8 8 4
8 c 6 9 8 4
NA
也是无;它可以很容易地用 0 替换:
merger.replace(None, 0)
x y v v.0 foo
0 b 1 1 7 2
1 b 3 2 7 2
2 b 6 3 7 2
3 a 1 4 0 0
4 a 3 5 0 0
5 a 6 6 0 0
6 c 1 7 8 4
7 c 3 8 8 4
8 c 6 9 8 4