datatable.rbind()¶
Produce a new frame by appending rows of several frames
.
This function is equivalent to:
dt.Frame().rbind(*frames, force=force, by_names=by_names)
Parameters¶
Frame
| List[Frame]
| None
bool
If True
, then the frames are allowed to have mismatching set of
columns (either different counts or different names). Any gaps in
the data will be filled with NAs.
In addition, when this parameter is True
, rbind will no longer
produce an error when combining columns of unrelated types.
Instead, both columns will be converted into strings.
bool
Whether to match column names when rbinding.
Frame
A new frame that is created by appending rows from frames
.
See also¶
cbind()
– function for col-binding several frames.dt.Frame.rbind()
– Frame method for rbinding some frames to another.
Examples¶
from datatable import dt
DT1 = dt.Frame({"Weight": [5, 4, 6], "Height": [170, 172, 180]})
DT1
Weight | Height | ||
---|---|---|---|
int32 | int32 | ||
0 | 5 | 170 | |
1 | 4 | 172 | |
2 | 6 | 180 |
DT2 = dt.Frame({"Height": [180, 181, 169], "Weight": [4, 4, 5]})
DT2
Weight | Height | ||
---|---|---|---|
int32 | int32 | ||
0 | 4 | 180 | |
1 | 4 | 181 | |
2 | 5 | 169 |
dt.rbind(DT1, DT2)
Weight | Height | ||
---|---|---|---|
int32 | int32 | ||
0 | 5 | 170 | |
1 | 4 | 172 | |
2 | 6 | 180 | |
3 | 4 | 180 | |
4 | 4 | 181 | |
5 | 5 | 169 |
rbind()
by default combines frames by names. The frames can also be
bound by column position by setting the bynames
parameter to False
:
dt.rbind(DT1, DT2, bynames = False)
Weight | Height | ||
---|---|---|---|
int32 | int32 | ||
0 | 5 | 170 | |
1 | 4 | 172 | |
2 | 6 | 180 | |
3 | 180 | 4 | |
4 | 181 | 4 | |
5 | 169 | 5 |
If the number of columns are not equal or the column names are different,
you can force the row binding by setting the force
parameter to True
:
DT2["Age"] = dt.Frame([25, 50, 67])
DT2
Weight | Height | Age | ||
---|---|---|---|---|
int32 | int32 | int32 | ||
0 | 4 | 180 | 25 | |
1 | 4 | 181 | 50 | |
2 | 5 | 169 | 67 |
dt.rbind(DT1, DT2, force = True)
Weight | Height | Age | ||
---|---|---|---|---|
int32 | int32 | int32 | ||
0 | 5 | 170 | NA | |
1 | 4 | 172 | NA | |
2 | 6 | 180 | NA | |
3 | 4 | 180 | 25 | |
4 | 4 | 181 | 50 | |
5 | 5 | 169 | 67 |