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
impl DataFrame
pub fn header(&self) -> &Vec<String>
pub fn header_mut(&mut self) -> &mut Vec<String>
sourcepub fn set_header(&mut self, new_header: Vec<&str>)
pub fn set_header(&mut self, new_header: Vec<&str>)
Change header
pub fn spread(&self) -> String
sourcepub fn as_types(&mut self, dtypes: Vec<DType>)
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);
}
sourcepub fn drop(&mut self, col_header: &str)
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 SimpleParquet for DataFrame
impl SimpleParquet for DataFrame
source§impl WithNetCDF for DataFrame
impl WithNetCDF for DataFrame
source§fn read_nc_by_header(
file_path: &str,
header: Vec<&str>,
) -> Result<Self, Box<dyn Error>>
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
impl WithParquet for DataFrame
impl StructuralPartialEq for DataFrame
Auto Trait Implementations§
impl Freeze for DataFrame
impl RefUnwindSafe for DataFrame
impl Send for DataFrame
impl Sync for DataFrame
impl Unpin for DataFrame
impl UnwindSafe for DataFrame
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
🔬This is a nightly-only experimental API. (
clone_to_uninit
)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