]> Humopery - polarsbop.git/commitdiff
some basic manipulations
authorErik Mackdanz <erikmack@gmail.com>
Thu, 23 Nov 2023 20:47:22 +0000 (14:47 -0600)
committerErik Mackdanz <erikmack@gmail.com>
Thu, 23 Nov 2023 20:47:22 +0000 (14:47 -0600)
Cargo.toml
src/main.rs

index faabd4a67eb817ea847bb2cb40526c8172edffc5..2623bb26894c065c3e9ceb446f382735b6b29584 100644 (file)
@@ -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
index 4f4e47f0074e0454b0d06fc98ed899f85fde8ca5..68ad3c70d0eee520608aa3a0349f2d6717c0996d 100644 (file)
@@ -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);
-    
 }