pub fn apply_at_idx<F, S>(&mut self, idx: usize, f: F) -> Result<&mut Self>
    where
        F: FnOnce(&Series) -> S,
        S: IntoSeries,
    {
        let width = self.width();
        let col = self.columns.get_mut(idx).ok_or_else(|| {
            PolarsError::OutOfBounds(
                format!(
                    "Column index: {} outside of DataFrame with {} columns",
                    idx, width
                )
                .into(),
            )
        })?;
        let name = col.name().to_string();
        let _ = mem::replace(col, f(col).into_series());

        // make sure the name remains the same after applying the closure
        unsafe {
            let col = self.columns.get_unchecked_mut(idx);
            col.rename(&name);
        }
        self.register_mutation()?;
        Ok(self)
    }
/// Apply a closure to a column at index `idx`. This is the recommended way to do in place
/// modification.
///
/// # Example
///
/// ```rust
/// use polars::prelude::*;
/// let s0 = Series::new("foo", &["ham", "spam", "egg"]);
/// let s1 = Series::new("ascii", &[70, 79, 79]);
/// let mut df = DataFrame::new(vec![s0, s1]).unwrap();
///
/// // Add 32 to get lowercase ascii values
/// df.apply_at_idx(1, |s| s + 32);
/// ```
/// Results in:
///
/// ```text
/// +--------+-------+
/// | foo    | ascii |
/// | ---    | ---   |
/// | str    | i32   |
/// +========+=======+
/// | "ham"  | 102   |
/// +--------+-------+
/// | "spam" | 111   |
/// +--------+-------+
/// | "egg"  | 111   |
/// +--------+-------+
/// ```
Apply a closure to a column at index `idx`. This is the recommended way to do in place
modification.
Apply a closure to a column at index ` idx ` . This is the recommended way to do in place modification .
pub fn apply_at_idx<F, S>(&mut self, idx: usize, f: F) -> Result<&mut Self>
    where
        F: FnOnce(&Series) -> S,
        S: IntoSeries,
    {
        let width = self.width();
        let col = self.columns.get_mut(idx).ok_or_else(|| {
            PolarsError::OutOfBounds(
                format!(
                    "Column index: {} outside of DataFrame with {} columns",
                    idx, width
                )
                .into(),
            )
        })?;
        let name = col.name().to_string();
        let _ = mem::replace(col, f(col).into_series());
        // make sure the name remains the same after applying the closure
        unsafe {
            let col = self.columns.get_unchecked_mut(idx);
            col.rename(&name);
        }
        self.register_mutation()?;
        Ok(self)
    }
pub fn apply_at_idx < F , S > ( & mut self , idx : usize , f : F ) -> Result < & mut Self > where F : FnOnce ( & Series ) -> S , S : IntoSeries , { let width = self . width ( ) ; let col = self . columns . get_mut ( idx ) . ok_or_else ( | | { PolarsError :: OutOfBounds ( format ! ( " " idx width ) . into ( ) , ) } ) ? ; let name = col . name ( ) . to_string ( ) ; let _ = mem :: replace ( col , f ( col ) . into_series ( ) ) ; // make sure the name remains the same after applying the closure unsafe { let col = self . columns . get_unchecked_mut ( idx ) ; col . rename ( & name ) ; } self . register_mutation ( ) ? ; Ok ( self ) }
Apply a closure to a column at index `idx`.
Apply a closure to a column at index ` idx ` .
&mut self
idx
usize
f
F
&mut self
idx
usize
f
F
example


Add 32 to get lowercase ascii values
df.apply_at_idx(1, |s| s + 32);
```
Results in.


Add 32 to get lowercase ascii values df . apply_at_idx ( 1 |s| s + 32 ) ; ` ` ` Results in .