-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
42 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,51 @@ | ||
use polars::prelude::*; | ||
fn main() { | ||
// --8<-- [start:series] | ||
use polars::prelude::*; | ||
|
||
fn main() -> Result<(), Box<dyn std::error::Error>> { | ||
let s = Series::new("a", &[1, 2, 3, 4, 5]); | ||
|
||
// --8<-- [start:series] | ||
let s = Series::new("a", &[1, 2, 3, 4, 5]) | ||
println!("{}", s); | ||
// --8<-- [end:series] | ||
|
||
println!("{}", s) | ||
// --8<-- [end:series] | ||
// --8<-- [start:dataframe] | ||
use chrono::NaiveDate; | ||
|
||
// --8<-- [start:dataframe] | ||
use chrono::NaiveDate; | ||
let df: DataFrame = df!( | ||
"integer" => &[1, 2, 3, 4, 5], | ||
"date" => &[ | ||
NaiveDate::from_ymd_opt(2025, 1, 1).unwrap().and_hms_opt(0, 0, 0).unwrap(), | ||
NaiveDate::from_ymd_opt(2025, 1, 2).unwrap().and_hms_opt(0, 0, 0).unwrap(), | ||
NaiveDate::from_ymd_opt(2025, 1, 3).unwrap().and_hms_opt(0, 0, 0).unwrap(), | ||
NaiveDate::from_ymd_opt(2025, 1, 4).unwrap().and_hms_opt(0, 0, 0).unwrap(), | ||
NaiveDate::from_ymd_opt(2025, 1, 5).unwrap().and_hms_opt(0, 0, 0).unwrap(), | ||
], | ||
"float" => &[4.0, 5.0, 6.0, 7.0, 8.0] | ||
) | ||
.unwrap(); | ||
|
||
let df: DataFrame = df!( | ||
"integer" => &[1, 2, 3, 4, 5], | ||
"date" => &[ | ||
NaiveDate::from_ymd_opt(2025, 1, 1).unwrap().and_hms_opt(0, 0, 0).unwrap(), | ||
NaiveDate::from_ymd_opt(2025, 1, 2).unwrap().and_hms_opt(0, 0, 0).unwrap(), | ||
NaiveDate::from_ymd_opt(2025, 1, 3).unwrap().and_hms_opt(0, 0, 0).unwrap(), | ||
NaiveDate::from_ymd_opt(2025, 1, 4).unwrap().and_hms_opt(0, 0, 0).unwrap(), | ||
NaiveDate::from_ymd_opt(2025, 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] | ||
|
||
println!("{}", df) | ||
// --8<-- [end:dataframe] | ||
// --8<-- [start:head] | ||
let df_head = df.head(Some(3)); | ||
|
||
// --8<-- [start:head] | ||
let df_head = df.head(Some(3)) | ||
println!("{}", df_head); | ||
// --8<-- [end:head] | ||
|
||
println("{}", df_head) | ||
// --8<-- [end:head] | ||
// --8<-- [start:tail] | ||
let df_tail = df.tail(Some(3)); | ||
|
||
// --8<-- [start:tail] | ||
let df_tail = df.tail(Some(3)) | ||
println!("{}", df_tail); | ||
// --8<-- [end:tail] | ||
|
||
println!("{}", df_tail) | ||
// --8<-- [end:tail] | ||
// --8<-- [start:sample] | ||
let n = Series::new("", &[2]); | ||
let sampled_df = df.sample_n(&n, false, false, None).unwrap(); | ||
|
||
// --8<-- [start:sample] | ||
let s1 = Series::new("", &[2]); | ||
println!("{}", sampled_df); | ||
// --8<-- [end:sample] | ||
|
||
let sampled_df = df.sample_n(&s1, false, false, None); | ||
|
||
println!("{:?}", sampled_df); | ||
// --8<-- [end:sample] | ||
|
||
// --8<-- [start:describe] | ||
// Not available in Rust | ||
// --8<-- [end:describe] | ||
|
||
Ok(()) | ||
} | ||
// --8<-- [start:describe] | ||
// Not available in Rust | ||
// --8<-- [end:describe] | ||
} |