Struct rusty_data::datatable::DataColumn
[−]
[src]
pub struct DataColumn { pub name: Option<String>, // some fields omitted }
A data column consisting of Strings.
Fields
name: Option<String>
The name associated with the DataColumn.
Methods
impl DataColumn
[src]
fn empty() -> DataColumn
Constructs an empty data column.
fn len(&self) -> usize
Gets the length of the data column.
fn data(&self) -> &Vec<String>
Gets an immutable reference to the underlying data.
fn categories(&self) -> Option<HashMap<String, usize>>
Gets an immutable reference to the categories Option.
fn update_categories(&mut self)
Update the categories set using the current data.
Examples
use rusty_data::datatable::DataColumn; let mut dc = DataColumn::empty(); dc.push("Class1".to_string()); dc.push("Class2".to_string()); dc.push("Class2".to_string()); dc.update_categories(); let categories = dc.categories().unwrap(); // Note that `contains` requires a reference so we pass an &str. assert!(categories.contains_key("Class2")); assert_eq!(categories.len(), 2);
fn numeric_category_data<T: Zero + One>(&self) -> Result<Vec<Vec<T>>, DataError>
Produce a numerical vector representation of the category data.
Examples
use rusty_data::datatable::DataColumn; let mut dc = DataColumn::empty(); dc.push("Class1".to_string()); dc.push("Class2".to_string()); dc.push("Class2".to_string()); dc.update_categories(); let data = dc.numeric_category_data::<f64>().unwrap(); println!("The data is: {:?}", data);
fn push(&mut self, val: String)
Pushes a new &str to the column.
fn get_as<T: FromStr>(&self, idx: usize) -> Result<T, DataError>
Try to get the element at the index as the requested type.
Failures
- DataCastError : The element at the given index could not be parsed to this type.
fn shrink_to_fit(&mut self)
Shrink the column to fit the data.
fn into_vec<T: FromStr>(self) -> Result<Vec<T>, DataError>
Consumes self and returns a Vec of the requested type.
Failures
- DataCastError : Returned when the data cannot be parsed to the requested type.
fn cast<T: FromStr>(&self) -> Option<Vec<T>>
Cast the data to the requested type.
Returns a Vec of the requested type wrapped in an option.
fn into_iter_cast<U: FromStr>(
self
) -> Map<IntoIter<String>, fn(_: String) -> Result<U, <U as FromStr>::Err>> where
U: FromStr,
self
) -> Map<IntoIter<String>, fn(_: String) -> Result<U, <U as FromStr>::Err>> where
U: FromStr,
Consumes self and returns an iterator which parses the data to the specified type returning results.
The iterator will return a result on next()
detailing
the outcome of the parse.