Skip to main content

extract_columns

Function extract_columns 

Source
pub fn extract_columns<P: AsRef<Path>>(
    path: P,
    columns: &[&str],
) -> Result<Vec<Vec<String>>, CsvSliceError>
Expand description

Extracts specific columns from a CSV file by column name.

§Parameters

  • path - Path to the CSV file. Can be any type that can be converted to a Path.
  • columns - Array of column names to extract.

§Returns

  • Result<Vec<Vec<String>>, CsvSliceError> - A vector of vectors containing the extracted column data on success, or a CsvSliceError on failure.

§Example

use csv_slice::extract_columns;
let data = extract_columns("data.csv", &["Name", "Email"]).unwrap();
// This extracts the Name and Email columns from data.csv