I have been struggling with getting a working example of calculating a rolling minimum using polars (0.34.2). I would think something like the below code should work, but the latest version of polars doesn't want to accept an integer for window_size, it wants Duration instead, and I can't figure that part out. Does anyone have a working example that I can learn from? TIA.
let df = df! {
"Date" => &["2012-05-18", "2012-05-21", "2012-05-22", "2012-05-23"],
"Low" => &[38.0, 34.0, 31.0, 32.0]
}.unwrap();
let options = RollingOptions {
window_size: 3, // Window size
min_periods: 1, // Minimum number of observations in window required to have a value
center: false, // Set to true to set the labels at the center of the window
weights: None, // Optional weights for the window
by: None, // Optional Series to perform operation by
};
// Calculate rolling minimum
let rolling_min = df.column("Low").unwrap().rolling_min(options).unwrap();
// Print the result
println!("Rolling minimum: {:?}", rolling_min);