Skip to main content

DataFrame

Struct DataFrame 

Source
pub struct DataFrame { /* private fields */ }
Expand description

A columnar data structure. Each column is a named, typed array. All columns must have the same length.

Implementations§

Source§

impl DataFrame

Source

pub fn new(columns: Vec<Column>) -> Result<Self, DataFrameError>

Create a new DataFrame from columns. All columns must have the same length. Empty vec produces an empty DataFrame.

Source

pub fn empty() -> Self

Create an empty DataFrame (no columns, no rows).

Source

pub fn height(&self) -> usize

Number of rows.

Source

pub fn width(&self) -> usize

Number of columns.

Source

pub fn is_empty(&self) -> bool

Whether the DataFrame has no columns.

Source

pub fn column(&self, name: &str) -> Result<&Column, DataFrameError>

Get a column by name.

Source

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

Get all column names.

Source

pub fn columns(&self) -> &[Column]

Get all columns as a slice.

Source

pub fn schema(&self) -> Schema

Get the schema (column names and types).

Source

pub fn row(&self, index: usize) -> Option<Vec<Scalar>>

Get a row as a vector of Scalars.

Source

pub fn with_column(&self, col: Column) -> Result<Self, DataFrameError>

Add or replace a column. If a column with the same name exists, it is replaced.

Source§

impl DataFrame

Source

pub fn filter(&self, mask: &[bool]) -> Result<Self, DataFrameError>

Filter rows by a boolean mask. Mask length must equal height.

Source

pub fn filter_by( &self, column: &str, predicate: impl Fn(&Scalar) -> bool, ) -> Result<Self, DataFrameError>

Filter rows by a predicate applied to a named column. Each row’s value is extracted as a Scalar and passed to the predicate.

Source§

impl DataFrame

Source

pub fn group_by(&self, cols: &[&str]) -> Result<GroupBy<'_>, DataFrameError>

Group the DataFrame by specified columns. Returns a GroupBy that can be aggregated.

Source§

impl DataFrame

Source

pub fn join( &self, other: &DataFrame, on: &[&str], how: JoinType, ) -> Result<DataFrame, DataFrameError>

Join two DataFrames on shared key column names.

Equivalent to self.join_on(other, on, on, how) — both tables use the same column names as join keys.

Source

pub fn join_on( &self, other: &DataFrame, left_on: &[&str], right_on: &[&str], how: JoinType, ) -> Result<DataFrame, DataFrameError>

Join two DataFrames with potentially different key column names.

left_on columns from self, right_on columns from other. Key columns must have the same count. Column name collisions in non-key columns are resolved with _left / _right suffixes.

Source§

impl DataFrame

Source

pub fn select(&self, names: &[&str]) -> Result<Self, DataFrameError>

Select a subset of columns by name. Returns an error if any column is not found.

Source

pub fn drop_columns(&self, names: &[&str]) -> Self

Drop columns by name. Silently ignores names not found.

Source

pub fn rename_column( &self, old: &str, new: &str, ) -> Result<Self, DataFrameError>

Rename a column. Returns error if the column is not found.

Source§

impl DataFrame

Source

pub fn sort(&self, by: &str, descending: bool) -> Result<Self, DataFrameError>

Sort by a single column. Nulls sort last.

Source

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

Take the first n rows.

Source

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

Take the last n rows.

Source§

impl DataFrame

Source

pub fn to_json(&self) -> Result<String, DataFrameError>

Serialize the DataFrame to a JSON string (array of row objects).

Source

pub fn to_json_writer<W: Write>(&self, writer: W) -> Result<(), DataFrameError>

Serialize the DataFrame to a writer.

Source

pub fn to_json_file(&self, path: &Path) -> Result<(), DataFrameError>

Write to a JSON file at the given path.

Source

pub fn from_json(json: &str) -> Result<Self, DataFrameError>

Deserialize a DataFrame from a JSON string (array of row objects).

Source

pub fn from_json_reader<R: Read>(reader: R) -> Result<Self, DataFrameError>

Deserialize a DataFrame from a reader.

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

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