merge

Syntax

merge(left, right, [how='inner'])

Details

Merge 2 indexed series or 2 indexed matrices.

The merge function in DolphinDB and the merge function in pandas share similar core functionality, but differ in the following aspects:

Comparison Dimension DolphinDB merge Python Pandas merge
Core functionality Joins two indexed series or indexed matrices objects. Performs alignment and merging based on row labels. Joins two DataFrame objects. The join is done on columns or indexes.
Primary design purpose Handles panel data and supports alignment operations for time-series or cross-sectional data. Implements relational database JOIN operations (e.g., inner, left, right, outer join).
Input objects left, right: must be indexed series or indexed matrices. left, right: DataFrame or named Series.
Key parameters Supports how ('inner', 'outer', 'left', 'right', 'asof' (DolphinDB specific)). Supports how, on, left_on, right_on, left_index, right_index, sort, suffixes, etc., with richer functionality.

Parameters

left and right are both indexed series, or are both indexed matrices.

how is a string indicating how to merge left and right. It can take the value of 'inner', 'outer', 'left', 'right', or 'asof'. The default value is 'inner'.

Returns

A matrix.

Examples

a =  indexed series(2012.01.01..2012.01.04, 1..4)
b =  indexed series([2012.01.01, 2012.01.03, 2012.01.05, 2012.01.06], 5..8)
merge(a, b);
series1 series2
2012.01.01 1 5
2012.01.03 3 6
merge(a, b, 'left');
series1 series2
2012.01.01 1 5
2012.01.02 2
2012.01.03 3 6
2012.01.04 4
m1 = matrix([1.2, 7.8, 4.6, 5.1, 9.5], [0.15, 1.26, 0.45, 1.02, 0.33]).rename!([2012.01.01, 2015.02.01, 2015.03.01, 2015.04.01, 2015.05.01], `x1`x2).setindexed matrices!()
m2 = matrix([1.0, 2.0, 3.0, 4.0], [0.14, 0.26, 0.35, 0.48]).rename!([2015.02.01, 2015.02.16, 2015.05.01, 2015.05.02], `y1`y2).setindexed matrices!()
m = merge(m1, m2, 'asof');
x1 x2 y1 y2
2012.01.01 1.2 0.15
2015.02.01 7.8 1.26 1 0.14
2015.03.01 4.6 0.45 2 0.26
2015.04.01 5.1 1.02 2 0.26
2015.05.01 9.5 0.33 3 0.35