Skip to content

Instantly share code, notes, and snippets.

@Crispy13
Last active July 14, 2023 09:52
Show Gist options
  • Save Crispy13/1eba99c7f81b960e3104c82b1e92749f to your computer and use it in GitHub Desktop.
Save Crispy13/1eba99c7f81b960e3104c82b1e92749f to your computer and use it in GitHub Desktop.
Read TSV files with Rust.
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