Module polars_io::csv

source ·
Available on crate features csv or json only.
Expand description

§(De)serializing CSV files

§Maximal performance

Currently CsvReader::new has an extra copy. If you want optimal performance in CSV parsing/ reading, it is advised to use CsvReader::from_path.

§Write a DataFrame to a csv file.

§Example

use polars_core::prelude::*;
use polars_io::prelude::*;
use std::fs::File;

fn example(df: &mut DataFrame) -> PolarsResult<()> {
    let mut file = File::create("example.csv").expect("could not create file");

    CsvWriter::new(&mut file)
    .include_header(true)
    .with_separator(b',')
    .finish(df)
}

§Read a csv file to a DataFrame

§Example

use polars_core::prelude::*;
use polars_io::prelude::*;
use std::fs::File;

fn example() -> PolarsResult<DataFrame> {
    // always prefer `from_path` as that is fastest.
    CsvReader::from_path("iris_csv")?
            .has_header(true)
            .finish()
}

Modules§

Structs§

Enums§

Functions§

  • Read the number of rows without parsing columns useful for count(*) queries