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 PartialEq for DataFrame
impl PartialEq for DataFrame
impl StructuralPartialEq for DataFrame
Auto Trait Implementations§
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