Struct peroxide::structure::dataframe::DataFrame

source ·
pub struct DataFrame {
    pub data: Vec<Series>,
    pub ics: Vec<String>,
}
Expand description

Generic DataFrame structure

§Example

extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    // 1. Series to DataFrame
    // 1-1. Declare Series
    let a = Series::new(vec![1, 2, 3, 4]);
    let b = Series::new(vec![true, false, false, true]);
    let c = Series::new(vec![0.1, 0.2, 0.3, 0.4]);

    // 1-2. Declare DataFrame (default header: 0, 1, 2)
    let mut df = DataFrame::new(vec![a, b, c]);
    df.set_header(vec!["a", "b", "c"]);
    df.print(); // Pretty print for DataFrame

    // 2. Empty DataFrame
    let mut dg = DataFrame::new(vec![]);
    dg.push("a", Series::new(vec![1,2,3,4]));
    dg.push("b", Series::new(vec![true, false, false, true]));
    dg.push("c", Series::new(vec![0.1, 0.2, 0.3, 0.4]));
    dg.print();

    assert_eq!(df, dg);
}

Fields§

§data: Vec<Series>§ics: Vec<String>

Implementations§

source§

impl DataFrame

source

pub fn new(v: Vec<Series>) -> Self

Declare new DataFrame with Vec<Series>

source

pub fn header(&self) -> &Vec<String>

source

pub fn header_mut(&mut self) -> &mut Vec<String>

source

pub fn set_header(&mut self, new_header: Vec<&str>)

Change header

source

pub fn push(&mut self, name: &str, series: Series)

Push new pair of head, Series to DataFrame

source

pub fn row(&self, i: usize) -> DataFrame

Extract specific row as DataFrame

source

pub fn spread(&self) -> String

source

pub fn as_types(&mut self, dtypes: Vec<DType>)

Type casting for DataFrame

§Examples
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = Series::new(vec![1i32, 2, 3, 4]);
    let b = Series::new(vec![true, false, false, true]);
     
    let mut df = DataFrame::new(vec![a, b]);    // I32, Bool
    df.as_types(vec![USIZE, U8]);               // USIZE, U8

    let c = Series::new(vec![1usize, 2, 3, 4]);
    let d = Series::new(vec![1u8, 0, 0, 1]);
    let dg = DataFrame::new(vec![c, d]);

    assert_eq!(df, dg);
}
source

pub fn drop(&mut self, col_header: &str)

Drop specific column by header

§Examples
extern crate peroxide;
use peroxide::fuga::*;

fn main() {
    let a = Series::new(vec![1,2,3,4]);
    let b = Series::new(vec![5,6,7,8]);

    let mut df = DataFrame::new(vec![a.clone(), b]);
    df.set_header(vec!["a", "b"]);

    let mut dg = DataFrame::new(vec![a]);
    dg.set_header(vec!["a"]);

    df.drop("b");

    assert_eq!(df, dg);
}

Trait Implementations§

source§

impl Clone for DataFrame

source§

fn clone(&self) -> DataFrame

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for DataFrame

source§

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

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

impl Display for DataFrame

source§

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

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

impl Index<&str> for DataFrame

§

type Output = Series

The returned type after indexing.
source§

fn index(&self, index: &str) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl Index<usize> for DataFrame

§

type Output = Series

The returned type after indexing.
source§

fn index(&self, index: usize) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
source§

impl IndexMut<&str> for DataFrame

source§

fn index_mut(&mut self, index: &str) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl IndexMut<usize> for DataFrame

source§

fn index_mut(&mut self, index: usize) -> &mut Self::Output

Performs the mutable indexing (container[index]) operation. Read more
source§

impl PartialEq for DataFrame

source§

fn eq(&self, other: &DataFrame) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Printable for DataFrame

source§

fn print(&self)

source§

impl StructuralPartialEq for DataFrame

Auto Trait Implementations§

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> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.
source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

source§

fn vzip(self) -> V