diff --git a/docs/src/python/user-guide/basics/series-dataframes.py b/docs/src/python/user-guide/basics/series-dataframes.py index 3171da06adbc..edc1a2a25c3c 100644 --- a/docs/src/python/user-guide/basics/series-dataframes.py +++ b/docs/src/python/user-guide/basics/series-dataframes.py @@ -5,27 +5,6 @@ print(s) # --8<-- [end:series] -# --8<-- [start:minmax] -s = pl.Series("a", [1, 2, 3, 4, 5]) -print(s.min()) -print(s.max()) -# --8<-- [end:minmax] - -# --8<-- [start:string] -s = pl.Series("a", ["polar", "bear", "arctic", "polar fox", "polar bear"]) -s2 = s.str.replace("polar", "pola") -print(s2) -# --8<-- [end:string] - -# --8<-- [start:dt] -from datetime import date - -start = date(2001, 1, 1) -stop = date(2001, 1, 9) -s = pl.date_range(start, stop, interval="2d", eager=True) -print(s.dt.day()) -# --8<-- [end:dt] - # --8<-- [start:dataframe] from datetime import datetime diff --git a/docs/src/rust/Cargo.toml b/docs/src/rust/Cargo.toml index da1ce364ab03..fea9ad2e736c 100644 --- a/docs/src/rust/Cargo.toml +++ b/docs/src/rust/Cargo.toml @@ -35,6 +35,9 @@ path = "user-guide/basics/joins.rs" name = "user-guide-basics-reading-writing" path = "user-guide/basics/reading-writing.rs" required-features = ["polars/json"] +[[bin]] +name = "user-guide-basics-series-dataframes" +path = "user-guide/basics/series-dataframes.rs" [[bin]] name = "user-guide-concepts-contexts" diff --git a/docs/src/rust/user-guide/basics/series-dataframes.rs b/docs/src/rust/user-guide/basics/series-dataframes.rs new file mode 100644 index 000000000000..2334f7718569 --- /dev/null +++ b/docs/src/rust/user-guide/basics/series-dataframes.rs @@ -0,0 +1,51 @@ +fn main() { + // --8<-- [start:series] + use polars::prelude::*; + + let s = Series::new("a", &[1, 2, 3, 4, 5]); + + println!("{}", s); + // --8<-- [end:series] + + // --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(); + + println!("{}", df); + // --8<-- [end:dataframe] + + // --8<-- [start:head] + let df_head = df.head(Some(3)); + + println!("{}", df_head); + // --8<-- [end:head] + + // --8<-- [start:tail] + let df_tail = df.tail(Some(3)); + + 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(); + + println!("{}", sampled_df); + // --8<-- [end:sample] + + // --8<-- [start:describe] + // Not available in Rust + // --8<-- [end:describe] +}