Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
Move import down to the chrono example
Browse files Browse the repository at this point in the history
  • Loading branch information
stinodego committed Sep 12, 2023
1 parent 48113ec commit 1a69ff8
Showing 1 changed file with 24 additions and 21 deletions.
45 changes: 24 additions & 21 deletions docs/src/rust/getting-started/series-dataframes.rs
Original file line number Diff line number Diff line change
@@ -1,54 +1,57 @@

fn main() -> Result<(), Box<dyn std::error::Error>>{
fn main() -> Result<(), Box<dyn std::error::Error>> {
// --8<-- [start:series]
use polars::prelude::*;
use chrono::prelude::*; // This will be needed for the exercise below:

let s = Series::new("a", [1, 2, 3, 4, 5]);
println!("{}", s);
// --8<-- [end:series]

// --8<-- [start:minmax]
let s = Series::new("a", [1, 2, 3, 4, 5]);
// The use of generics is necessary for the type system
println!("{}", s.min::<u64>().unwrap());
println!("{}", s.max::<u64>().unwrap());
// --8<-- [end:minmax]

// --8<-- [start:string]
// This operation is not directly available on the Series object yet, only on the DataFrame
// --8<-- [end:string]

// --8<-- [start:dt]
// This operation is not directly available on the Series object yet, only on the DataFrame
// --8<-- [end:dt]

// --8<-- [start:dataframe]
let df: DataFrame = df!("integer" => &[1, 2, 3, 4, 5],
"date" => &[
NaiveDate::from_ymd_opt(2022, 1, 1).unwrap().and_hms_opt(0, 0, 0).unwrap(),
NaiveDate::from_ymd_opt(2022, 1, 2).unwrap().and_hms_opt(0, 0, 0).unwrap(),
NaiveDate::from_ymd_opt(2022, 1, 3).unwrap().and_hms_opt(0, 0, 0).unwrap(),
NaiveDate::from_ymd_opt(2022, 1, 4).unwrap().and_hms_opt(0, 0, 0).unwrap(),
NaiveDate::from_ymd_opt(2022, 1, 5).unwrap().and_hms_opt(0, 0, 0).unwrap()
],
"float" => &[4.0, 5.0, 6.0, 7.0, 8.0]
).expect("should not fail");
use chrono::prelude::*;

let df: DataFrame = df!(
"integer" => &[1, 2, 3, 4, 5],
"date" => &[
NaiveDate::from_ymd_opt(2022, 1, 1).unwrap().and_hms_opt(0, 0, 0).unwrap(),
NaiveDate::from_ymd_opt(2022, 1, 2).unwrap().and_hms_opt(0, 0, 0).unwrap(),
NaiveDate::from_ymd_opt(2022, 1, 3).unwrap().and_hms_opt(0, 0, 0).unwrap(),
NaiveDate::from_ymd_opt(2022, 1, 4).unwrap().and_hms_opt(0, 0, 0).unwrap(),
NaiveDate::from_ymd_opt(2022, 1, 5).unwrap().and_hms_opt(0, 0, 0).unwrap()
],
"float" => &[4.0, 5.0, 6.0, 7.0, 8.0],
)
.unwrap();

println!("{}", df);
// --8<-- [end:dataframe]

// --8<-- [start:head]
println!("{}", df.head(Some(3)));
// --8<-- [end:head]

// --8<-- [start:tail]
println!("{}", df.tail(Some(3)));
// --8<-- [end:tail]

// --8<-- [start:sample]
println!("{}", df.sample_n(2, false, true, None)?);
// --8<-- [end:sample]

// --8<-- [start:describe]
println!("{:?}", df.describe(None));
// --8<-- [end:describe]
Expand Down

0 comments on commit 1a69ff8

Please sign in to comment.