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
impl DataFrame
Sourcepub fn new(columns: Vec<Column>) -> Result<Self, DataFrameError>
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.
Sourcepub fn column_names(&self) -> Vec<&str>
pub fn column_names(&self) -> Vec<&str>
Get all column names.
Sourcepub fn with_column(&self, col: Column) -> Result<Self, DataFrameError>
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
impl DataFrame
Sourcepub fn filter(&self, mask: &[bool]) -> Result<Self, DataFrameError>
pub fn filter(&self, mask: &[bool]) -> Result<Self, DataFrameError>
Filter rows by a boolean mask. Mask length must equal height.
Source§impl DataFrame
impl DataFrame
Sourcepub fn join(
&self,
other: &DataFrame,
on: &[&str],
how: JoinType,
) -> Result<DataFrame, DataFrameError>
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.
Sourcepub fn join_on(
&self,
other: &DataFrame,
left_on: &[&str],
right_on: &[&str],
how: JoinType,
) -> Result<DataFrame, DataFrameError>
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
impl DataFrame
Sourcepub fn select(&self, names: &[&str]) -> Result<Self, DataFrameError>
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.
Sourcepub fn drop_columns(&self, names: &[&str]) -> Self
pub fn drop_columns(&self, names: &[&str]) -> Self
Drop columns by name. Silently ignores names not found.
Sourcepub fn rename_column(
&self,
old: &str,
new: &str,
) -> Result<Self, DataFrameError>
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
impl DataFrame
Sourcepub fn to_json(&self) -> Result<String, DataFrameError>
pub fn to_json(&self) -> Result<String, DataFrameError>
Serialize the DataFrame to a JSON string (array of row objects).
Sourcepub fn to_json_writer<W: Write>(&self, writer: W) -> Result<(), DataFrameError>
pub fn to_json_writer<W: Write>(&self, writer: W) -> Result<(), DataFrameError>
Serialize the DataFrame to a writer.
Sourcepub fn to_json_file(&self, path: &Path) -> Result<(), DataFrameError>
pub fn to_json_file(&self, path: &Path) -> Result<(), DataFrameError>
Write to a JSON file at the given path.
Sourcepub fn from_json(json: &str) -> Result<Self, DataFrameError>
pub fn from_json(json: &str) -> Result<Self, DataFrameError>
Deserialize a DataFrame from a JSON string (array of row objects).
Sourcepub fn from_json_reader<R: Read>(reader: R) -> Result<Self, DataFrameError>
pub fn from_json_reader<R: Read>(reader: R) -> Result<Self, DataFrameError>
Deserialize a DataFrame from a reader.