Last active
July 14, 2023 09:52
-
-
Save Crispy13/1eba99c7f81b960e3104c82b1e92749f to your computer and use it in GitHub Desktop.
Read TSV files with Rust.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use polars::prelude::*; // cargo add polars | |
pub fn load_tsv(file_path:&PathBuf) -> DataFrame { | |
let mut df = CsvReader::from_path(file_path) | |
.unwrap() | |
.with_delimiter(b'\t') | |
.infer_schema(None) // if None polars look through all data, so when loading big data it probably takes long time. You can limit the records polars will look into. | |
.has_header(false) // if it has then 'true' | |
.finish() | |
.unwrap(); | |
df.set_column_names(&["Breakfast", "Lunch", "Dinner", "Sum"]).unwrap(); // if tsv has a header comment this out. | |
df | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment