pub trait DataFrameJoinOps: IntoDf {
// Provided methods
fn join(
&self,
other: &DataFrame,
left_on: impl IntoIterator<Item = impl Into<PlSmallStr>>,
right_on: impl IntoIterator<Item = impl Into<PlSmallStr>>,
args: JoinArgs,
) -> Result<DataFrame, PolarsError> { ... }
fn inner_join(
&self,
other: &DataFrame,
left_on: impl IntoIterator<Item = impl Into<PlSmallStr>>,
right_on: impl IntoIterator<Item = impl Into<PlSmallStr>>,
) -> Result<DataFrame, PolarsError> { ... }
fn left_join(
&self,
other: &DataFrame,
left_on: impl IntoIterator<Item = impl Into<PlSmallStr>>,
right_on: impl IntoIterator<Item = impl Into<PlSmallStr>>,
) -> Result<DataFrame, PolarsError> { ... }
fn full_join(
&self,
other: &DataFrame,
left_on: impl IntoIterator<Item = impl Into<PlSmallStr>>,
right_on: impl IntoIterator<Item = impl Into<PlSmallStr>>,
) -> Result<DataFrame, PolarsError> { ... }
}
Available on crate feature
polars-ops
only.Provided Methods§
Sourcefn join(
&self,
other: &DataFrame,
left_on: impl IntoIterator<Item = impl Into<PlSmallStr>>,
right_on: impl IntoIterator<Item = impl Into<PlSmallStr>>,
args: JoinArgs,
) -> Result<DataFrame, PolarsError>
fn join( &self, other: &DataFrame, left_on: impl IntoIterator<Item = impl Into<PlSmallStr>>, right_on: impl IntoIterator<Item = impl Into<PlSmallStr>>, args: JoinArgs, ) -> Result<DataFrame, PolarsError>
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 |
+--------+----------------------+---------------------+
Sourcefn inner_join(
&self,
other: &DataFrame,
left_on: impl IntoIterator<Item = impl Into<PlSmallStr>>,
right_on: impl IntoIterator<Item = impl Into<PlSmallStr>>,
) -> Result<DataFrame, PolarsError>
fn inner_join( &self, other: &DataFrame, left_on: impl IntoIterator<Item = impl Into<PlSmallStr>>, right_on: impl IntoIterator<Item = impl Into<PlSmallStr>>, ) -> Result<DataFrame, PolarsError>
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"])
}
Sourcefn left_join(
&self,
other: &DataFrame,
left_on: impl IntoIterator<Item = impl Into<PlSmallStr>>,
right_on: impl IntoIterator<Item = impl Into<PlSmallStr>>,
) -> Result<DataFrame, PolarsError>
fn left_join( &self, other: &DataFrame, left_on: impl IntoIterator<Item = impl Into<PlSmallStr>>, right_on: impl IntoIterator<Item = impl Into<PlSmallStr>>, ) -> Result<DataFrame, PolarsError>
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 |
+-----------------+--------+
Sourcefn full_join(
&self,
other: &DataFrame,
left_on: impl IntoIterator<Item = impl Into<PlSmallStr>>,
right_on: impl IntoIterator<Item = impl Into<PlSmallStr>>,
) -> Result<DataFrame, PolarsError>
fn full_join( &self, other: &DataFrame, left_on: impl IntoIterator<Item = impl Into<PlSmallStr>>, right_on: impl IntoIterator<Item = impl Into<PlSmallStr>>, ) -> Result<DataFrame, PolarsError>
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.