Trait polars_ops::frame::join::DataFrameJoinOps

source ·
pub trait DataFrameJoinOps: IntoDf {
    // Provided methods
    fn join<I, S>(
        &self,
        other: &DataFrame,
        left_on: I,
        right_on: I,
        args: JoinArgs
    ) -> PolarsResult<DataFrame>
       where I: IntoIterator<Item = S>,
             S: AsRef<str> { ... }
    fn inner_join<I, S>(
        &self,
        other: &DataFrame,
        left_on: I,
        right_on: I
    ) -> PolarsResult<DataFrame>
       where I: IntoIterator<Item = S>,
             S: AsRef<str> { ... }
    fn left_join<I, S>(
        &self,
        other: &DataFrame,
        left_on: I,
        right_on: I
    ) -> PolarsResult<DataFrame>
       where I: IntoIterator<Item = S>,
             S: AsRef<str> { ... }
    fn full_join<I, S>(
        &self,
        other: &DataFrame,
        left_on: I,
        right_on: I
    ) -> PolarsResult<DataFrame>
       where I: IntoIterator<Item = S>,
             S: AsRef<str> { ... }
}

Provided Methods§

source

fn join<I, S>( &self, other: &DataFrame, left_on: I, right_on: I, args: JoinArgs ) -> PolarsResult<DataFrame>
where I: IntoIterator<Item = S>, S: AsRef<str>,

Generic join method. Can be used to join on multiple columns.

§Example
let df1: DataFrame = df!("Fruit" => &["Apple", "Banana", "Pear"],
                         "Phosphorus (mg/100g)" => &[11, 22, 12])?;
let df2: DataFrame = df!("Name" => &["Apple", "Banana", "Pear"],
                         "Potassium (mg/100g)" => &[107, 358, 115])?;

let df3: DataFrame = df1.join(&df2, ["Fruit"], ["Name"], JoinArgs::new(JoinType::Inner))?;
assert_eq!(df3.shape(), (3, 3));
println!("{}", df3);

Output:

shape: (3, 3)
+--------+----------------------+---------------------+
| Fruit  | Phosphorus (mg/100g) | Potassium (mg/100g) |
| ---    | ---                  | ---                 |
| str    | i32                  | i32                 |
+========+======================+=====================+
| Apple  | 11                   | 107                 |
+--------+----------------------+---------------------+
| Banana | 22                   | 358                 |
+--------+----------------------+---------------------+
| Pear   | 12                   | 115                 |
+--------+----------------------+---------------------+
source

fn inner_join<I, S>( &self, other: &DataFrame, left_on: I, right_on: I ) -> PolarsResult<DataFrame>
where I: IntoIterator<Item = S>, S: AsRef<str>,

Perform an inner join on two DataFrames.

§Example
fn join_dfs(left: &DataFrame, right: &DataFrame) -> PolarsResult<DataFrame> {
    left.inner_join(right, ["join_column_left"], ["join_column_right"])
}
source

fn left_join<I, S>( &self, other: &DataFrame, left_on: I, right_on: I ) -> PolarsResult<DataFrame>
where I: IntoIterator<Item = S>, S: AsRef<str>,

Perform a left outer join on two DataFrames

§Example
let df1: DataFrame = df!("Wavelength (nm)" => &[480.0, 650.0, 577.0, 1201.0, 100.0])?;
let df2: DataFrame = df!("Color" => &["Blue", "Yellow", "Red"],
                         "Wavelength nm" => &[480.0, 577.0, 650.0])?;

let df3: DataFrame = df1.left_join(&df2, ["Wavelength (nm)"], ["Wavelength nm"])?;
println!("{:?}", df3);

Output:

shape: (5, 2)
+-----------------+--------+
| Wavelength (nm) | Color  |
| ---             | ---    |
| f64             | str    |
+=================+========+
| 480             | Blue   |
+-----------------+--------+
| 650             | Red    |
+-----------------+--------+
| 577             | Yellow |
+-----------------+--------+
| 1201            | null   |
+-----------------+--------+
| 100             | null   |
+-----------------+--------+
source

fn full_join<I, S>( &self, other: &DataFrame, left_on: I, right_on: I ) -> PolarsResult<DataFrame>
where I: IntoIterator<Item = S>, S: AsRef<str>,

Perform a full outer join on two DataFrames

§Example
fn join_dfs(left: &DataFrame, right: &DataFrame) -> PolarsResult<DataFrame> {
    left.full_join(right, ["join_column_left"], ["join_column_right"])
}

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl DataFrameJoinOps for DataFrame

Implementors§