align method

List<DataFrame> align(
  1. DataFrame other, {
  2. String join = 'outer',
  3. int? axis,
  4. dynamic fillValue,
})

Align two DataFrames on their axes with specified join method.

Parameters:

  • other: DataFrame to align with
  • join: Type of alignment to perform
    • 'outer': Union of indices (default)
    • 'inner': Intersection of indices
    • 'left': Use calling DataFrame's index
    • 'right': Use other DataFrame's index
  • axis: Axis to align on (0 for rows, 1 for columns, null for both)
  • fillValue: Value to use for missing values

Returns: A tuple of (aligned_left, aligned_right) DataFrames

Example:

var df1 = DataFrame.fromMap({
  'A': [1, 2],
  'B': [3, 4],
}, index: ['a', 'b']);

var df2 = DataFrame.fromMap({
  'A': [5, 6],
  'C': [7, 8],
}, index: ['b', 'c']);

var aligned = df1.align(df2, join: 'outer');
// Both DataFrames will have index ['a', 'b', 'c'] and columns ['A', 'B', 'C']

Implementation

List<DataFrame> align(
  DataFrame other, {
  String join = 'outer',
  int? axis,
  dynamic fillValue,
}) {
  if (axis == null) {
    // Align both axes
    final rowAligned = _alignAxis(this, other, 0, join, fillValue);
    final fullyAligned =
        _alignAxis(rowAligned[0], rowAligned[1], 1, join, fillValue);
    return fullyAligned;
  } else {
    return _alignAxis(this, other, axis, join, fillValue);
  }
}