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);
}Sourcepub fn filter_by<F>(&self, column: &str, predicate: F) -> Result<DataFrame>
pub fn filter_by<F>(&self, column: &str, predicate: F) -> Result<DataFrame>
Filter DataFrame by specific column
Sourcepub fn select_rows(&self, indices: &[usize]) -> DataFrame
pub fn select_rows(&self, indices: &[usize]) -> DataFrame
Select rows based on indices
Sourcepub fn contains(&self, col_header: &str) -> bool
pub fn contains(&self, col_header: &str) -> bool
Check if the DataFrame contains a column with the given header
Sourcepub fn slice(&self, offset: usize, length: usize) -> DataFrame
pub fn slice(&self, offset: usize, length: usize) -> DataFrame
Return a slice of rows starting at offset with the given length
Sourcepub fn select(&self, columns: &[&str]) -> DataFrame
pub fn select(&self, columns: &[&str]) -> DataFrame
Select specific columns by name, returning a new DataFrame
Panics if any column name does not exist.
Sourcepub fn rename(&mut self, old: &str, new: &str)
pub fn rename(&mut self, old: &str, new: &str)
Rename a column in-place
Panics if the old column name does not exist.
Sourcepub fn column_names(&self) -> Vec<&str>
pub fn column_names(&self) -> Vec<&str>
Return column names as Vec<&str>
Sourcepub fn select_dtypes(&self, dtypes: &[DType]) -> DataFrame
pub fn select_dtypes(&self, dtypes: &[DType]) -> DataFrame
Select columns whose dtype is in the given list
Trait Implementations§
Source§impl SimpleParquet for DataFrame
Available on crate feature parquet only.
impl SimpleParquet for DataFrame
Available on crate feature
parquet only.Source§impl WithNetCDF for DataFrame
Available on crate feature nc only.
impl WithNetCDF for DataFrame
Available on crate feature
nc only.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
Available on crate feature parquet only.
impl WithParquet for DataFrame
Available on crate feature
parquet only.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§
§impl<T> ArchivePointee for T
impl<T> ArchivePointee for T
§type ArchivedMetadata = ()
type ArchivedMetadata = ()
The archived version of the pointer metadata for this type.
§fn pointer_metadata(
_: &<T as ArchivePointee>::ArchivedMetadata,
) -> <T as Pointee>::Metadata
fn pointer_metadata( _: &<T as ArchivePointee>::ArchivedMetadata, ) -> <T as Pointee>::Metadata
Converts some archived metadata to the pointer metadata for itself.
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§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§impl<T> LayoutRaw for T
impl<T> LayoutRaw for T
§fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
fn layout_raw(_: <T as Pointee>::Metadata) -> Result<Layout, LayoutError>
Returns the layout of the type.