Merge-Datatable
Command Description
Merget two databases according to specific join type
Command Prototype
dtTable = Datatable.MergeDataTable(dtLeftTable,dtRightTable,strHow,strLeftKey,strRightKey,bSort)
Parameter Description
Parameter | Required | Type | Default | Description |
---|---|---|---|---|
dtLeftTable | True | expression | leftTable | Datatable 1 to be merged |
dtRightTable | True | expression | rightTable | Datatable 2 to be merged |
strHow | True | enum | "inner" | The method to join two tables |
strLeftKey | True | string | "" | Column name of the left table to use as the basis for joining |
strRightKey | True | string | "" | Use column name of the right table as the basis for joining |
bSort | True | boolean | None | When it is set as True, it means during merge the output is ordered by the specified column values(for example the left_on column value specified previously) |
return
dtTable,The variable used to save the output of the command.
Demo
aryData = [["a", 1], ["b", 2], ["c", 3], ["d", 1]]
aryColumns = ["letter", "number"]
objDatatable = Datatable.BuildDataTable(aryData,aryColumns)
aryData2 = [["a", 19], ["b", 20]]
aryColumns2 = ["letter", "age"]
objDatatable2 = Datatable.BuildDataTable(aryData2,aryColumns2)
dtTable = Datatable.MergeDataTable(objDatatable,objDatatable2,"outer","letter","letter",false)
TracePrint(dtTable)
/*
letter number age
0 a 1 19.0
1 b 2 20.0
2 c 3 NaN
3 d 1 NaN
*/