Function read_csv_chunked

Source
pub fn read_csv_chunked<P, F>(
    path: P,
    config: Option<CsvReaderConfig>,
    chunk_size: usize,
    callback: F,
) -> Result<()>
where P: AsRef<Path>, F: FnMut(&[String], &Array2<String>) -> bool,
Expand description

Read a CSV file in chunks to process large files memory-efficiently

§Arguments

  • path - Path to the CSV file
  • config - Optional CSV reader configuration
  • chunk_size - Number of rows to read in each chunk
  • callback - Function to process each chunk

§Returns

  • Result<()> - Success or error

§Examples

use scirs2_io::csv::{read_csv_chunked, CsvReaderConfig};
use ndarray::Array2;

let config = CsvReaderConfig::default();
let mut total_rows = 0;

read_csv_chunked("large_data.csv", Some(config), 1000, |headers, chunk| {
    println!("Processing chunk with {} rows", chunk.shape()[0]);
    total_rows += chunk.shape()[0];
    true // continue processing
}).unwrap();

println!("Total rows processed: {}", total_rows);