pub fn hmean(&self, none_strategy: NullStrategy) -> Result<Option<Series>> {
        match self.columns.len() {
            0 => Ok(None),
            1 => Ok(Some(self.columns[0].clone())),
            _ => {
                let sum = self.hsum(none_strategy)?;

                let first: Cow<Series> = Cow::Owned(
                    self.columns[0]
                        .is_null()
                        .cast::<UInt32Type>()
                        .unwrap()
                        .into_series(),
                );
                let null_count = self.columns[1..]
                    .iter()
                    .map(Cow::Borrowed)
                    .fold(first, |acc, s| {
                        Cow::Owned(
                            acc.as_ref() + &s.is_null().cast::<UInt32Type>().unwrap().into_series(),
                        )
                    })
                    .into_owned();

                // value lengths: len - null_count
                let value_length: UInt32Chunked =
                    (self.width().sub(&null_count)).u32().unwrap().clone();

                // make sure that we do not divide by zero
                // by replacing with None
                let value_length = value_length
                    .set(&value_length.eq(0), None)?
                    .into_series()
                    .cast::<Float64Type>()?;

                Ok(sum.map(|sum| &sum / &value_length))
            }
        }
    }
/// Aggregate the column horizontally to their mean values
Aggregate the column horizontally to their mean values
Aggregate the column horizontally to their mean values
pub fn hmean(&self, none_strategy: NullStrategy) -> Result<Option<Series>> {
        match self.columns.len() {
            0 => Ok(None),
            1 => Ok(Some(self.columns[0].clone())),
            _ => {
                let sum = self.hsum(none_strategy)?;
                let first: Cow<Series> = Cow::Owned(
                    self.columns[0]
                        .is_null()
                        .cast::<UInt32Type>()
                        .unwrap()
                        .into_series(),
                );
                let null_count = self.columns[1..]
                    .iter()
                    .map(Cow::Borrowed)
                    .fold(first, |acc, s| {
                        Cow::Owned(
                            acc.as_ref() + &s.is_null().cast::<UInt32Type>().unwrap().into_series(),
                        )
                    })
                    .into_owned();
                // value lengths: len - null_count
                let value_length: UInt32Chunked =
                    (self.width().sub(&null_count)).u32().unwrap().clone();
                // make sure that we do not divide by zero
                // by replacing with None
                let value_length = value_length
                    .set(&value_length.eq(0), None)?
                    .into_series()
                    .cast::<Float64Type>()?;
                Ok(sum.map(|sum| &sum / &value_length))
            }
        }
    }
pub fn hmean ( & self , none_strategy : NullStrategy ) -> Result < Option < Series > > { match self . columns . len ( ) { 0 => Ok ( None ) , 1 => Ok ( Some ( self . columns [ 0 ] . clone ( ) ) ) , _ => { let sum = self . hsum ( none_strategy ) ? ; let first : Cow < Series > = Cow :: Owned ( self . columns [ 0 ] . is_null ( ) . cast :: < UInt32Type > ( ) . unwrap ( ) . into_series ( ) , ) ; let null_count = self . columns [ 1 .. ] . iter ( ) . map ( Cow :: Borrowed ) . fold ( first , | acc , s | { Cow :: Owned ( acc . as_ref ( ) + & s . is_null ( ) . cast :: < UInt32Type > ( ) . unwrap ( ) . into_series ( ) , ) } ) . into_owned ( ) ; // value lengths: len - null_count let value_length : UInt32Chunked = ( self . width ( ) . sub ( & null_count ) ) . u32 ( ) . unwrap ( ) . clone ( ) ; // make sure that we do not divide by zero // by replacing with None let value_length = value_length . set ( & value_length . eq ( 0 ) , None ) ? . into_series ( ) . cast :: < Float64Type > ( ) ? ; Ok ( sum . map ( | sum | & sum / & value_length ) ) } } }
Aggregate the column horizontally to their mean values
Aggregate the column horizontally to their mean values
&self
none_strategy
NullStrategy