DataFrame

Struct 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);
}
Source

pub fn filter_by<F>(&self, column: &str, predicate: F) -> Result<DataFrame>
where F: Fn(Scalar) -> bool,

Filter DataFrame by specific column

Source

pub fn mask(&self, mask: &Series) -> Result<DataFrame>

Mask DataFrame with a boolean Series

Source

pub fn select_rows(&self, indices: &[usize]) -> DataFrame

Select rows based on indices

Source

pub fn nrow(&self) -> usize

Number of rows (max column length)

Source

pub fn ncol(&self) -> usize

Number of columns

Source

pub fn shape(&self) -> (usize, usize)

Shape as (nrow, ncol)

Source

pub fn dtypes(&self) -> Vec<DType>

DType of each column

Source

pub fn is_empty(&self) -> bool

Check if the DataFrame has no columns or no rows

Source

pub fn contains(&self, col_header: &str) -> bool

Check if the DataFrame contains a column with the given header

Source

pub fn head(&self, n: usize) -> DataFrame

Return the first n rows

Source

pub fn tail(&self, n: usize) -> DataFrame

Return the last n rows

Source

pub fn slice(&self, offset: usize, length: usize) -> DataFrame

Return a slice of rows starting at offset with the given length

Source

pub fn select(&self, columns: &[&str]) -> DataFrame

Select specific columns by name, returning a new DataFrame

Panics if any column name does not exist.

Source

pub fn rename(&mut self, old: &str, new: &str)

Rename a column in-place

Panics if the old column name does not exist.

Source

pub fn column_names(&self) -> Vec<&str>

Return column names as Vec<&str>

Source

pub fn select_dtypes(&self, dtypes: &[DType]) -> DataFrame

Select columns whose dtype is in the given list

Source

pub fn describe(&self) -> DataFrame

Compute descriptive statistics for numeric columns

Returns a DataFrame with rows: count, mean, sd, min, max and one column per numeric column from the original DataFrame.

Source

pub fn sum(&self) -> DataFrame

Sum of each numeric column as a single-row DataFrame

Source

pub fn mean(&self) -> DataFrame

Mean of each numeric column as a single-row DataFrame

Trait Implementations§

Source§

impl Clone for DataFrame

Source§

fn clone(&self) -> DataFrame

Returns a duplicate 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

Available on crate feature parquet only.
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

Available on crate feature csv only.
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

Available on crate feature nc only.
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

Available on crate feature parquet only.
Source§

fn write_parquet( &self, file_path: &str, compression: Compression, ) -> 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
§

impl<T> ArchivePointee for T

§

type ArchivedMetadata = ()

The archived version of the pointer metadata for this type.
§

fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata

Converts some archived metadata to the pointer metadata for itself.
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, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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
§

impl<T> LayoutRaw for T

§

fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>

Returns the layout of the type.
§

impl<T, N1, N2> Niching<NichedOption<T, N1>> for N2
where T: SharedNiching<N1, N2>, N1: Niching<T>, N2: Niching<T>,

§

unsafe fn is_niched(niched: *const NichedOption<T, N1>) -> bool

Returns whether the given value has been niched. Read more
§

fn resolve_niched(out: Place<NichedOption<T, N1>>)

Writes data to out indicating that a T is niched.
§

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
§

impl<T> Pointee for T

§

type Metadata = ()

The metadata type for pointers and references to this type.
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§

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> Allocation for T
where T: RefUnwindSafe + Send + Sync,

§

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