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>
impl<I: PartialOrd + PartialEq + BlackJackData> DataFrame<I>
Sourcepub fn new() -> Self
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 DataFrameSourcepub fn filter_by_row<F>(&mut self, condition: F)
pub fn filter_by_row<F>(&mut self, condition: F)
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);Sourcepub fn drop_positions(&mut self, positions: impl Iterator<Item = usize>)
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);Sourcepub fn iter_rows(&self) -> impl Iterator<Item = Row<'_>>
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 elementsSourcepub fn iloc<Idx>(&self, idx: Idx) -> impl Iterator<Item = Row<'_>>where
Idx: IntoIterator<Item = usize>,
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);
}Sourcepub fn len(&self) -> usize
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);Sourcepub fn add_column<T: BlackJackData + 'static>(
&mut self,
series: Series<T>,
) -> Result<(), BlackJackError>
pub fn add_column<T: BlackJackData + 'static>( &mut self, series: Series<T>, ) -> Result<(), BlackJackError>
Add a column to this dataframe.
Sourcepub fn get_column_mut<'a, T>(
&mut self,
name: impl Into<&'a str>,
) -> Option<&mut Series<T>>where
T: BlackJackData + 'static,
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
Sourcepub fn get_column<'a, T>(&self, name: impl Into<&'a str>) -> Option<&Series<T>>where
T: BlackJackData + 'static,
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
Sourcepub fn get_column_infer<'a>(
&self,
name: impl Into<&'a str>,
) -> Option<GenericSeriesContainer>
pub fn get_column_infer<'a>( &self, name: impl Into<&'a str>, ) -> Option<GenericSeriesContainer>
Get column, infer
Sourcepub fn columns(&self) -> impl Iterator<Item = &str>
pub fn columns(&self) -> impl Iterator<Item = &str>
Get a list of column names in this dataframe as an iterator
Sourcepub fn groupby<T>(&self, keys: &Series<T>) -> DataFrameGroupBy<T>
pub fn groupby<T>(&self, keys: &Series<T>) -> DataFrameGroupBy<T>
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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