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

source§

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

source§

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

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

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

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 SimpleParquet for DataFrame

source§

fn write_parquet(&self, path: &str) -> Result<(), Box<dyn Error>>

source§

fn read_parquet(path: &str) -> Result<Self, Box<dyn Error>>

source§

impl WithCSV for DataFrame

source§

fn write_csv(&self, file_path: &str) -> Result<(), Box<dyn Error>>

Write csv file

source§

fn read_csv(file_path: &str, delimiter: char) -> Result<Self, Box<dyn Error>>

Read csv file with delimiter

source§

impl WithNetCDF for DataFrame

source§

fn write_nc(&self, file_path: &str) -> Result<(), Box<dyn Error>>

write netcdf file

source§

fn read_nc(file_path: &str) -> Result<Self, Box<dyn Error>>

Read netcdf to DataFrame

source§

fn read_nc_by_header( file_path: &str, header: Vec<&str>, ) -> Result<Self, Box<dyn Error>>

Read netcdf to DataFrame with specific header

§Example
#[macro_use]
extern crate peroxide;
use peroxide::fuga::*;

fn main() -> Result<(), Box<dyn Error>> {
    let mut df = DataFrame::new(vec![]);
    df.push("a", Series::new(vec![1,2,3,4]));
    df.push("b", Series::new(vec!['a', 'b', 'c', 'd']));
    df.push("c", Series::new(c!(0.1, 0.2, 0.3, 0.4)));
    df.write_nc("example_data/doc_nc2.nc")?;

    let dg = DataFrame::read_nc_by_header("example_data/doc_nc2.nc", vec!["a", "c"])?;

    df.drop("b");

    assert_eq!(df, dg);
     
    Ok(())
}
source§

impl WithParquet for DataFrame

source§

fn write_parquet( &self, file_path: &str, compression: CompressionOptions, ) -> Result<(), Box<dyn Error>>

Write DataFrame to parquet

source§

fn read_parquet(file_path: &str) -> Result<Self, Box<dyn Error>>
where Self: Sized,

Read parquet to DataFrame

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

source§

unsafe fn clone_to_uninit(&self, dst: *mut T)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dst. Read more
source§

impl<T> DynClone for T
where T: Clone,

source§

fn __clone_box(&self, _: Private) -> *mut ()

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
§

impl<T> Pointable for T

§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
§

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

Initializes a with the given initializer. Read more
§

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

Dereferences the given pointer. Read more
§

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

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

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

impl<T> ToOwned for T
where T: Clone,

source§

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

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

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

§

fn vzip(self) -> V

§

impl<T> Ungil for T
where T: Send,