Struct blackjack::series::Series

source ·
pub struct Series<T>where
    T: BlackJackData,
{ pub name: Option<String>, pub values: Vec<T>, /* private fields */ }
Expand description

Series struct for containing underlying Array and other meta data.

Fields§

§name: Option<String>

Name of the series, if added to a dataframe without a name, it will be assigned a default name equalling the cound of columns in the dataframe.

§values: Vec<T>

The underlying values of the Series

Implementations§

Constructor methods for Series<T>

Create a new Series struct from an integer range with one step increments.

Example
use blackjack::prelude::*;
 
let series: Series<i32> = Series::arange(0, 10);

Convert the series into another DType (creates a new series)

Example
use blackjack::prelude::*;

let series: Series<i32> = Series::arange(0, 10);
assert_eq!(series[0].dtype(), DType::I32);
let new_series = series.astype::<f64>().unwrap();
assert_eq!(new_series[0].dtype(), DType::F64);

Convert this series into another DType (consumes current series)

Example
use blackjack::prelude::*;

let series: Series<i32> = Series::arange(0, 10);
assert_eq!(series[0].dtype(), DType::I32);
let new_series = series.into_type::<f64>().unwrap();
assert_eq!(new_series[0].dtype(), DType::F64);

Get a series of the unique elements held in this series

Example
use blackjack::prelude::*;
 
let series: Series<i32> = Series::from_vec(vec![1, 2, 1, 0, 1, 0, 1, 1]);
let unique: Series<i32> = series.unique();
assert_eq!(unique, Series::from_vec(vec![0, 1, 2]));

Create a new Series struct from a vector, where T is supported by BlackJackData.

Example
use blackjack::prelude::*;
 
let series: Series<i32> = Series::from_vec(vec![1, 2, 3]);

Convert the series to a Vec
Type Annotations required Will coerce elements into the desired DType primitive, just as [SeriesTrait::astype()].

Example
use blackjack::prelude::*;
 
let series = Series::from_vec(vec![1_f64, 2_f64, 3_f64]);
 
assert_eq!(
    series.clone().into_vec(),
    vec![1_f64, 2_f64, 3_f64]
);

Set the name of a series

Get the name of the series; Series may not be assigned a string, so an Option is returned.

Example
use blackjack::prelude::*;
 
let mut series = Series::from_vec(vec![1, 2, 3]);
series.set_name("my-series");
 
assert_eq!(series.name(), Some("my-series".to_string()));

Finds the returns a Series containing the mode(s) of the current Series

Calculate the variance of the series
NOTE that whatever type is determined is what the values are cast to during calculation of the variance.

ie. series.var::<i32>() will cast each element into i32 as input for calculating the variance, and yield a i32 value. If you want all values to be calculated as f64 then specify that in the type annotation.

Calculate the standard deviation of the series

Example
use blackjack::prelude::*;
 
let series = Series::arange(0, 10).astype::<f32>().unwrap();
 
let std = series.std().unwrap(); // Ok(2.8722...)
assert!(std > 2.87);
assert!(std < 2.88);

Sum a given series, yielding the same type as the elements stored in the series.

Average / Mean of a given series - Requires specifying desired float return annotation

Example:
use blackjack::prelude::*;
 
let series = Series::arange(0, 5);
let mean = series.mean();
 
match mean {
    Ok(result) => {
        println!("Result is: {}", &result);
        assert_eq!(result, 2.0);
    },
    Err(err) => {
        panic!("Was unable to compute mean, error: {}", err);
    }
}

Calculate the quantile of the series

Example:
use blackjack::prelude::*;
 
let series = Series::arange(0, 100).astype::<f32>().unwrap();
let qtl = series.quantile(0.5).unwrap(); // `49.5_f32`
 
assert!(qtl < 49.51);
assert!(qtl > 49.49);

Calculate the median of a series

Find the minimum of the series. If several elements are equally minimum, the first element is returned. If it’s empty, an Error will be returned.

Example
use blackjack::prelude::*;
 
let series: Series<i32> = Series::arange(10, 100);
 
assert_eq!(series.min(), Ok(10));

Exibits the same behavior and usage of [SeriesTrait::min], only yielding the Result of a maximum.

Determine the length of the Series

Determine if series is empty.

Get the dtype, returns None if series dtype is unknown. in such a case, calling .astype() to coerce all types to a single type is needed.

Append a BlackJackData element to the Series

Example
use blackjack::prelude::*;
 
let mut series = Series::from_vec(vec![0, 1, 2]);
assert_eq!(series.len(), 3);
 
series.append(3);
assert_eq!(series.len(), 4);

As boxed pointer, recoverable by Box::from_raw(ptr) or SeriesTrait::from_raw(*mut Self)

Create from raw pointer

Group by method for grouping elements in a Series by key.

Example
use blackjack::prelude::*;

let series = Series::from_vec(vec![1, 2, 3, 1, 2, 3]);
let keys   = Series::from_vec(vec![4, 5, 6, 4, 5, 6]);

let grouped: Series<i32> = series.groupby(keys).sum();
assert_eq!(grouped.len(), 3);

let mut vals = grouped.into_vec();
vals.sort();
assert_eq!(vals, vec![2, 4, 6]);

Trait Implementations§

Support series + scalar

The resulting type after applying the + operator.
Performs the + operation. Read more

Support series += scalar

Performs the += operation. Read more
Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
Deserialize this value from the given Serde deserializer. Read more
Formats the value using the given formatter. Read more

Support series - scalar

The resulting type after applying the / operator.
Performs the / operation. Read more

Support series += scalar

Performs the /= operation. Read more
The returned type after indexing.
Performs the indexing (container[index]) operation. Read more
Performs the mutable indexing (container[index]) operation. Read more

Support series * scalar

The resulting type after applying the * operator.
Performs the * operation. Read more
Performs the *= operation. Read more
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Support series - scalar

The resulting type after applying the - operator.
Performs the - operation. Read more

Support series -= scalar

Performs the -= operation. Read more

Auto Trait Implementations§

Blanket Implementations§

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The alignment of pointer.
The type for initializers.
Initializes a with the given initializer. Read more
Dereferences the given pointer. Read more
Mutably dereferences the given pointer. Read more
Drops the object pointed to by the given pointer. Read more
The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
Converts the given value to a String. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.