pub fn hstack_mut(&mut self, columns: &[Series]) -> Result<&mut Self> {
        let mut names = self.hash_names();
        let height = self.height();
        // first loop check validity. We don't do this in a single pass otherwise
        // this DataFrame is already modified when an error occurs.
        for col in columns {
            if col.len() != height {
                return Err(PolarsError::ShapeMisMatch(
                    format!("Could not horizontally stack Series. The Series length {} differs from the DataFrame height: {}", col.len(), height).into()));
            }

            let name = col.name();
            if names.contains(name) {
                return Err(PolarsError::Duplicate(
                    format!(
                        "Cannot do hstack operation. Column with name: {} already exists",
                        name
                    )
                    .into(),
                ));
            }
            names.insert(name.to_string());
        }
        self.hstack_mut_no_checks(columns)
    }
/// Add multiple Series to a DataFrame
/// This expects the Series to have the same length.
///
/// # Example
///
/// ```
/// use polars::prelude::*;
/// fn stack(df: &mut DataFrame, columns: &[Series]) {
///     df.hstack_mut(columns);
/// }
/// ```
Add multiple Series to a DataFrame
This expects the Series to have the same length.
Add multiple Series to a DataFrame This expects the Series to have the same length .
pub fn hstack_mut(&mut self, columns: &[Series]) -> Result<&mut Self> {
        let mut names = self.hash_names();
        let height = self.height();
        // first loop check validity. We don't do this in a single pass otherwise
        // this DataFrame is already modified when an error occurs.
        for col in columns {
            if col.len() != height {
                return Err(PolarsError::ShapeMisMatch(
                    format!("Could not horizontally stack Series. The Series length {} differs from the DataFrame height: {}", col.len(), height).into()));
            }
            let name = col.name();
            if names.contains(name) {
                return Err(PolarsError::Duplicate(
                    format!(
                        "Cannot do hstack operation. Column with name: {} already exists",
                        name
                    )
                    .into(),
                ));
            }
            names.insert(name.to_string());
        }
        self.hstack_mut_no_checks(columns)
    }
pub fn hstack_mut ( & mut self , columns : & [ Series ] ) -> Result < & mut Self > { let mut names = self . hash_names ( ) ; let height = self . height ( ) ; // first loop check validity. We don't do this in a single pass otherwise // this DataFrame is already modified when an error occurs. for col in columns { if col . len ( ) != height { return Err ( PolarsError :: ShapeMisMatch ( format ! ( " " col len ( ) height ) . into ( ) ) ) ; } let name = col . name ( ) ; if names . contains ( name ) { return Err ( PolarsError :: Duplicate ( format ! ( " " name ) . into ( ) , ) ) ; } names . insert ( name . to_string ( ) ) ; } self . hstack_mut_no_checks ( columns ) }
Add multiple Series to a DataFrame
This expects the Series to have the same length.
Add multiple Series to a DataFrame This expects the Series to have the same length .
&mut self
columns
&[Series]
&mut self
columns
&[Series]
example
```
use polars::prelude::*;
fn stack(df: &mut DataFrame, columns: &[Series]) {
df.hstack_mut(columns);
}
```
` ` ` use polars :: prelude :: * ; fn stack ( df : &mut DataFrame columns : & [ Series ] ) { df . hstack_mut ( columns ) ; } ` ` `