DataFrameJoinOps

Trait DataFrameJoinOps 

Source
pub trait DataFrameJoinOps: IntoDf {
    // Provided methods
    fn join(
        &self,
        other: &DataFrame,
        left_on: impl IntoIterator<Item = impl AsRef<str>>,
        right_on: impl IntoIterator<Item = impl AsRef<str>>,
        args: JoinArgs,
        options: Option<JoinTypeOptions>,
    ) -> PolarsResult<DataFrame> { ... }
    fn inner_join(
        &self,
        other: &DataFrame,
        left_on: impl IntoIterator<Item = impl AsRef<str>>,
        right_on: impl IntoIterator<Item = impl AsRef<str>>,
    ) -> PolarsResult<DataFrame> { ... }
    fn left_join(
        &self,
        other: &DataFrame,
        left_on: impl IntoIterator<Item = impl AsRef<str>>,
        right_on: impl IntoIterator<Item = impl AsRef<str>>,
    ) -> PolarsResult<DataFrame> { ... }
    fn full_join(
        &self,
        other: &DataFrame,
        left_on: impl IntoIterator<Item = impl AsRef<str>>,
        right_on: impl IntoIterator<Item = impl AsRef<str>>,
    ) -> PolarsResult<DataFrame> { ... }
}

Provided Methods§

Source

fn join( &self, other: &DataFrame, left_on: impl IntoIterator<Item = impl AsRef<str>>, right_on: impl IntoIterator<Item = impl AsRef<str>>, args: JoinArgs, options: Option<JoinTypeOptions>, ) -> PolarsResult<DataFrame>

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),
None)?;
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( &self, other: &DataFrame, left_on: impl IntoIterator<Item = impl AsRef<str>>, right_on: impl IntoIterator<Item = impl AsRef<str>>, ) -> PolarsResult<DataFrame>

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( &self, other: &DataFrame, left_on: impl IntoIterator<Item = impl AsRef<str>>, right_on: impl IntoIterator<Item = impl AsRef<str>>, ) -> PolarsResult<DataFrame>

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( &self, other: &DataFrame, left_on: impl IntoIterator<Item = impl AsRef<str>>, right_on: impl IntoIterator<Item = impl AsRef<str>>, ) -> PolarsResult<DataFrame>

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"])
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl DataFrameJoinOps for DataFrame

Implementors§