From: Erik Mackdanz Date: Thu, 23 Nov 2023 20:47:22 +0000 (-0600) Subject: some basic manipulations X-Git-Url: https://git.humopery.space/?a=commitdiff_plain;h=c0f9fc9e46e8ace0d920215f4c509854325623e2;p=polarsbop.git some basic manipulations --- diff --git a/Cargo.toml b/Cargo.toml index faabd4a..2623bb2 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -8,3 +8,6 @@ edition = "2021" [dependencies] polars = { version = "0.35.4", features = ["lazy", "fmt", "partition_by", "http", "streaming", "async", "aws", "json", "random"] } polars-io = { version = "0.35.4", features = ["csv", "aws", "fmt", "http", "json"] } + +[build] +rustflags = ["-C", "link-arg=-fuse-ld=lld"] \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 4f4e47f..68ad3c7 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,13 +1,35 @@ -// use polars::prelude_core::*; -// use polars::prelude_io::*; use polars::prelude::*; use polars_io::csv::CsvReader; fn main() { + + // set some columns to be parsed as numeric + let mut schema_override = Schema::new(); + let _ = schema_override.with_column("2022".into(),DataType::Float64); + let schema_override = + Some(Arc::new(schema_override)); + + // Some string values in numeric fields should be ignored + let null_values = + Some(NullValues::AllColumns(vec!("Reported".to_string(),"Estimated".to_string()))); + + // read and parse from disk let df = CsvReader::from_path("data/bop.csv").unwrap() .has_header(true) + .with_dtypes(schema_override) + .with_null_values(null_values) .finish().unwrap(); + // one country + let df = df.filter(&df.column("Country Name").unwrap(). + equal("France").unwrap()).unwrap(); + + // values not status + let df = df.filter(&df.column("Attribute").unwrap(). + equal("Value").unwrap()).unwrap(); + + // just a few columns + let df = df.select(["Country Name","Indicator Name","Indicator Code","2022"]).unwrap(); + println!("df: {:?}",df); - }