Skip to main content

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

ParameterRequiredTypeDefaultDescription
dtLeftTableTrueexpressionleftTableDatatable 1 to be merged
dtRightTableTrueexpressionrightTableDatatable 2 to be merged
strHowTrueenum"inner"The method to join two tables
strLeftKeyTruestring""Column name of the left table to use as the basis for joining
strRightKeyTruestring""Use column name of the right table as the basis for joining
bSortTruebooleanNoneWhen 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
*/