Skip to content

Instantly share code, notes, and snippets.

View Crispy13's full-sized avatar

Crispy13

  • South Korea
View GitHub Profile
use std::fmt::Write;
use polars::prelude::*;
fn make_sorted_array_series(input: Vec<String>, datatype: &DataType) -> Vec<String> {
input
.into_iter()
.map(|s| {
let splited = s.split(",");
@Crispy13
Crispy13 / slice_polars_series.rs
Created July 14, 2023 09:55
Slice polars Series | Rust
use polars::prelude::*;
fn main() {
let s = Series::new("a", 0..100.collect::<Vec<i64>>);
println!("{:?}", s.slice(20, 10)); // 20..30
}
@Crispy13
Crispy13 / load_tsv.rs
Last active July 14, 2023 09:52
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();