DataFrame

Struct DataFrame 

Source
pub struct DataFrame<I>{ /* private fields */ }
Expand description

The container for Series<T> objects, allowing for additional functionality

Implementations§

Source§

impl<I: PartialOrd + PartialEq + BlackJackData> DataFrame<I>

Source

pub fn new() -> Self

Create a new DataFrame struct

§Example
use blackjack::prelude::*;

let mut df: DataFrame<i32> = DataFrame::new();  // `i32` indicates index type of DataFrame
Source

pub fn filter_by_row<F>(&mut self, condition: F)
where F: Fn(&Row<'_>) -> bool,

Filter the dataframe by iterating over its Rows.

§Example
let mut s1 = Series::from(0..5);
s1.set_name("col1");

let mut s2 = Series::from(10..15);
s2.set_name("col2");

let mut s3 = Series::from_vec(vec![
    "foo".to_string(),
    "bar".to_string(),
    "foo".to_string(),
    "bar".to_string(),
    "foo".to_string(),
]);
s3.set_name("col3");

let mut df = DataFrame::new();
assert!(df.add_column(s1).is_ok());
assert!(df.add_column(s2).is_ok());
assert!(df.add_column(s3).is_ok());

// Before filtering, we're len 5
assert_eq!(df.len(), 5);

df.filter_by_row(|row| row["col1"] == Datum::I32(&0));

// After filtering, we're len 4 and first element of 'col1' is now 1
assert_eq!(df.len(), 4);

// Filter by string foo,
df.filter_by_row(|row| row["col3"] != Datum::STR(&"foo".to_string()));
assert_eq!(df.len(), 2);
Source

pub fn drop_positions(&mut self, positions: impl Iterator<Item = usize>)

Drop positions within the Series

§Example

let mut df = DataFrame::new();
assert!(df.add_column(Series::from(0..10)).is_ok());

assert_eq!(df.len(), 10);
df.drop_positions(0..5);  // Iterator of `usize` items
assert_eq!(df.len(), 5);
Source

pub fn iter_rows(&self) -> impl Iterator<Item = Row<'_>>

Iterator over rows of a dataframe where each element contained is a reference

§Example

let rows = df.iter_rows().collect::<Vec<Row>>();
assert_eq!(rows.len(), 4);  // Four rows
assert!(rows.iter().all(|r| r.data.len() == 2));  // Each row has two elements
Source

pub fn iloc<Idx>(&self, idx: Idx) -> impl Iterator<Item = Row<'_>>
where Idx: IntoIterator<Item = usize>,

Select rows of the DataFrame based on positional index

§Example
use blackjack::prelude::*;

let mut df = DataFrame::new();
 let s1 = Series::from_vec(vec![0, 1, 2, 3]);
 let s2 = Series::from_vec(vec![1, 2, 3, 4]);

 assert!(df.add_column(s1).is_ok());
 assert!(df.add_column(s2).is_ok());

 let rows = df.iloc(vec![1]).collect::<Vec<Row>>();

 // First column is s1, second element is 1
 if let Datum::I32(val) = rows[0].data[0].data {
     assert_eq!(val, &1);
 }

 // second column is s2, second element is 2
 if let Datum::I32(val) = rows[0].data[1].data {
     assert_eq!(val, &2);
 }
Source

pub fn len(&self) -> usize

Length of the dataframe

§Example
use blackjack::prelude::*;

let mut df = DataFrame::new();
assert_eq!(df.len(), 0);

let series: Series<i32> = Series::arange(0, 10);
df.add_column(series).unwrap();

assert_eq!(df.len(), 10);
Source

pub fn is_empty(&self) -> bool

Quickly identify if the dataframe is empty.

Source

pub fn add_column<T: BlackJackData + 'static>( &mut self, series: Series<T>, ) -> Result<(), BlackJackError>
where Vec<I>: FromIterator<i32>,

Add a column to this dataframe.

Source

pub fn get_column_mut<'a, T>( &mut self, name: impl Into<&'a str>, ) -> Option<&mut Series<T>>
where T: BlackJackData + 'static,

Retrieves a mutable reference to the column

Source

pub fn get_column<'a, T>(&self, name: impl Into<&'a str>) -> Option<&Series<T>>
where T: BlackJackData + 'static,

Retrieves a reference to a column

Source

pub fn get_column_infer<'a>( &self, name: impl Into<&'a str>, ) -> Option<GenericSeriesContainer>

Get column, infer

Source

pub fn columns(&self) -> impl Iterator<Item = &str>

Get a list of column names in this dataframe as an iterator

Source

pub fn n_columns(&self) -> usize

Get the number of columns for this dataframe

Source

pub fn groupby<T>(&self, keys: &Series<T>) -> DataFrameGroupBy<T>
where for<'de> T: BlackJackData + Deserialize<'de> + ToPrimitive + 'static,

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

Trait Implementations§

Source§

impl<I> Debug for DataFrame<I>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<I> Default for DataFrame<I>

Source§

fn default() -> DataFrame<I>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<I> Freeze for DataFrame<I>

§

impl<I> !RefUnwindSafe for DataFrame<I>

§

impl<I> !Send for DataFrame<I>

§

impl<I> !Sync for DataFrame<I>

§

impl<I> Unpin for DataFrame<I>
where I: Unpin,

§

impl<I> !UnwindSafe for DataFrame<I>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.