withLeftJoinOn method
A new data frame representing a left join on that
.
Example:
final left = petals.withColumns(["id", "petal_length"]),
right = sepals.withColumns(["id", "sepal_length"]);
print("Left: $left");
print("Right: $right");
print("Left Join:");
print(left.withLeftJoinOn(right, pivot: "id"));
Left:
.---.------------.
|id |petal_length|
:---+------------:
|1 |1.4 |
|2 |1.4 |
|3 |1.3 |
|4 |1.5 |
|51 |4.7 |
|52 |4.5 |
|53 |4.9 |
|54 |4.0 |
|101|6.0 |
|102|5.1 |
|103|5.9 |
|104|5.6 |
'---'------------'
Right:
.---.------------.
|id |sepal_length|
:---+------------:
|3 |4.7 |
|4 |4.6 |
|5 |5.0 |
|6 |5.4 |
|53 |6.9 |
|54 |5.5 |
|55 |6.5 |
|56 |5.7 |
|103|7.1 |
|104|6.3 |
|105|6.5 |
|106|7.6 |
'---'------------'
Left Join:
.---.------------.--------.------------.
|id |petal_length|right_id|sepal_length|
:---+------------+--------+------------:
|1 |1.4 |NaN |NaN |
|2 |1.4 |NaN |NaN |
|3 |1.3 |3 |4.7 |
|4 |1.5 |4 |4.6 |
|51 |4.7 |NaN |NaN |
|52 |4.5 |NaN |NaN |
|53 |4.9 |53 |6.9 |
|54 |4.0 |54 |5.5 |
|101|6.0 |NaN |NaN |
|102|5.1 |NaN |NaN |
|103|5.9 |103 |7.1 |
|104|5.6 |104 |6.3 |
'---'------------'--------'------------'
Implementation
DataFrame withLeftJoinOn(
DataFrame that, {
required String pivot,
String? thatPivot,
}) {
thatPivot = thatPivot ?? pivot;
final ids = categoricColumns.containsKey(pivot)
? {...categoricColumns[pivot]!.values}
: {...numericColumns[pivot]!.values};
return _join(this, that, pivot, thatPivot, ids);
}