pub struct Column { /* private fields */ }Expand description
One named column of a Table.
A column pairs the values of one source column with the name that the source gives it. The name is fixed when the column is built.
§Examples
use dataset_ml::table::{Column, ColumnData};
use ndarray::array;
let column = Column::new("petal_width", ColumnData::Numeric(array![0.2, 1.4]));
assert_eq!(column.name(), "petal_width");
assert_eq!(column.len(), 2);
assert_eq!(column.as_numeric().unwrap()[0], 0.2);
// An `as_*` method returns `None` for every other variant.
assert!(column.as_string().is_none());Implementations§
Source§impl Column
impl Column
Sourcepub fn new(name: &'static str, data: ColumnData) -> Self
pub fn new(name: &'static str, data: ColumnData) -> Self
Sourcepub fn data(&self) -> &ColumnData
pub fn data(&self) -> &ColumnData
Sourcepub fn data_mut(&mut self) -> &mut ColumnData
pub fn data_mut(&mut self) -> &mut ColumnData
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Whether the column holds no sample.
§Returns
bool-trueif the column holds no sample, andfalseif it holds at least one.
Sourcepub fn as_numeric(&self) -> Option<&Array1<f64>>
pub fn as_numeric(&self) -> Option<&Array1<f64>>
The values, if the column is ColumnData::Numeric.
§Returns
Some(&Array1<f64>)- the values, one per sample.None- if the column holds another variant.
Sourcepub fn as_integer(&self) -> Option<&Array1<i64>>
pub fn as_integer(&self) -> Option<&Array1<i64>>
The values, if the column is ColumnData::Integer.
§Returns
Some(&Array1<i64>)- the values, one per sample.None- if the column holds another variant.
Sourcepub fn as_string(&self) -> Option<&Array1<String>>
pub fn as_string(&self) -> Option<&Array1<String>>
The values, if the column is ColumnData::String.
§Returns
Some(&Array1<String>)- the values, one per sample.None- if the column holds another variant.
Sourcepub fn as_bytes(&self) -> Option<&Array2<u8>>
pub fn as_bytes(&self) -> Option<&Array2<u8>>
The values, if the column is ColumnData::Bytes.
§Returns
Some(&Array2<u8>)- the rows, one per sample.None- if the column holds another variant.
Sourcepub fn to_numeric(&self) -> Option<Array1<f64>>
pub fn to_numeric(&self) -> Option<Array1<f64>>
The values as f64, one per sample.
§Returns
Some(Array1<f64>)- the values.ColumnData::Numericreturns them unchanged, andColumnData::Integerconverts each one.None- if the column isColumnData::String, which has no numeric reading, orColumnData::Bytes, which holds more than one value per sample. For aBytescolumn, useTable::numeric_matrix.
§Notes
An i64 above 2^53 loses precision as an f64.
Trait Implementations§
impl StructuralPartialEq for Column
Auto Trait Implementations§
impl Freeze for Column
impl RefUnwindSafe for Column
impl Send for Column
impl Sync for Column
impl Unpin for Column
impl UnsafeUnpin for Column
impl UnwindSafe for Column
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