Questions tagged [rust-polars]
271 questions
0
votes
1 answer
How do I get the distance to a previous occurrence of a value in Polars dataframe?
I want to efficiently find the distance from the current row to the previous occurrence. I know polars doesn't have indexes, but the formula would roughly be:
if prior_occurrence {
(current_row_index - prior_occurrence_index - 1)
} else {
…

Carbocarde
- 23
- 3
0
votes
1 answer
How do I filter a polars DataFrame by verifying if the value of a column is contained by an vector?
I have a dataframe which has the column "ID" with data typed as UInt32 and I have a vector named ids. I want to return a dataframe with the rows which "ID" value is contained by the vector ids.
MINIMAL WANTED EXAMPLE
use polars::df;
use…

sbb
- 144
- 8
0
votes
1 answer
Filter by time range in polars rust
I've some times series data which I would like to filter out a certain time range for each day. In my case I would like to filter out everything between 09:00 - 16:00 (i.e. I want all values from 09:00:00 to 16:00:00 inclusive).
I've tried and read…

nklsla
- 315
- 1
- 9
0
votes
1 answer
How to send a Polars `Expr`/`PyExpr`/`LogicalPlan` from Python to Rust?
In a single process, I could write an Polars Expr and then use it on DataFrame by with_column or select.
But in another scenario of realtime financial data, I have a rust process which has a lot of history and realtime data(DataFrame) as a server.…

Hakase
- 211
- 1
- 12
0
votes
1 answer
rust error: captured variable cannot escape `FnMut` closure body
The following code tries to asynchronously update a master dataframe df (from polars package) after getting a msg by concatenating it.
I have seen the "duplicate" posts on stack overflow but still don't understand what I am doing wrong. I just want…

ripbozo
- 45
- 4
0
votes
0 answers
How can I create an array from a CSV column encoded as a string using Polars in Rust?
I'm trying to write a Rust program which uses Polars to read a CSV. This particular CSV encodes an array of floats as a string.
In my program, I want to load the CSV into a DataFrame and then parse this column into an array of floats. In Python you…

maxcountryman
- 1,562
- 1
- 24
- 51
0
votes
1 answer
Is there a way to create a rust-polars Series from Vec?
how to create a Polars Series from Vec in rust?
use polars::prelude::*;
fn main() {
let mut col1: Vec = Vec::new();
col1.push(1);
col1.push(2);
let s1 = Series::new("col1", col1); // error: the trait…

Hadi
- 3
- 2
0
votes
1 answer
Is there a way to perform lazy operations in Polars on multiple frames at the same time?
Lazy more and query optimization in Polars is a great tool for saving on memory allocations and CPU usage for a single data frame. I wonder if there is a way to do this for multiple lazy frames as:
lpdf1 = pdf1.lazy()
lpdf2 =…

Mark Horvath
- 1,136
- 1
- 9
- 24
0
votes
0 answers
How to disable secientific notation in rust polars?
In rust polars, float number larger than 1e10 will be converted to secientific notation.
EXAMPLE:
use polars::prelude::*;
use polars::df;
use std::fs;
fn main() {
let mut df = df!{
"name" => ["a", "b", "c", "d", "e", "f"],
"b"…

Haoan
- 71
- 8
0
votes
1 answer
How to apply a closure to rust polars filter?
I'm processing data with polars in rust.
I need to filter out some values depend on previous line or item in other columns. I have read the documents but they seem to use internal methods to filter each single value, such as gt(), is_not_null()…

Haoan
- 71
- 8
0
votes
0 answers
How can I efficiently process many slices of a dataframe in Polars?
I have a dataset of time series data similar to the following:
let series_one = Series::new(
"a",
(0..4).into_iter().map(|v| v as f64).collect::>(),
);
let series_two = Series::new(
"b",
…

ChosunOne
- 684
- 8
- 26
0
votes
0 answers
Rust Polars: How to enforce i64 into f64 for dataframe
I use Rust polars for analyzing time-series data.
This csv data includes a lot of sensors' output, and some sensors are mostly 0 and otherwise float.
Default inference schema judge such colmuns as i64, but I want to judge columns as f64.
Current…

eksl
- 1
0
votes
0 answers
Rust Polars Dataframe to Tuple of vectors
I wanted to upload a polars dataframe to postgres using diesel.
In that insert_into() function is there, where i have to give tuple of vectors as an input to .values().
Can anyone give suggestion on how to upload that.
pub fn…
0
votes
1 answer
How to get right data with other dataframe
print(
(
df1.lazy()
.with_context(df2.lazy())
.select(
pl.col("df1_date")
.apply(lambda s: pl.col("df2_date").filter(pl.col("df2_date") >= s).first())
.alias("release_date")
)
…

Arzx
- 3
- 2
0
votes
2 answers
Selecting rows by id and calculating the mean value in Polars with Rust
I have the following dataframe and a vector of names.
name
age
panda
5
polarbear
7
seahorse
1
I would like to select rows by the names in the vector and calculate the average age of selected rows. I have the following code:
let names…

xosxos
- 167
- 1
- 6