Questions tagged [rust-polars]
271 questions
0
votes
2 answers
Get the original datatype values from a vector of AnyValues
I can convert many datatypes into the AnyValue enum in Rust Polars. but how do I convert them back to the original datatypes?
use polars::prelude::*;
fn main() {
let df = df!( "Fruit" => &["Apple", "Apple", "Pear"],
…

Robert
- 131
- 1
- 7
0
votes
1 answer
Repeat rows in a Polars DataFrame based on column value
I would like to expand the following Polars dataframe by repeating rows based on values in the quantity column.
Original DataFrame:
Fruit
Quantity
Apple
2
Banana
3
Expected…

NFern
- 1,706
- 17
- 18
0
votes
2 answers
Is there a way to cumulatively and distinctively expand list in polars
For distance, I want to accomplish conversion like below.
┌────────────┐
│ col │
│ --- │
│ list[str] │
╞════════════╡
│ ["a"] │
├╌╌╌╌╌╌╌╌╌╌╌╌┤
│ ["a", "b"] │
├╌╌╌╌╌╌╌╌╌╌╌╌┤
│ ["c"] …

amon
- 3
- 3
0
votes
1 answer
Returns a value referencing data owned by the current function? Why is this even a problem?
I'm trying to return a list of dictionaries(coming from a python background) from this rust function in which I read a csv file using polars library. I think the data type I need to use is Vec in this case, if not please correct me.
I've…

gkaykck
- 2,347
- 10
- 35
- 52
0
votes
1 answer
Rust Polars Series compare to scalar not working
I am trying to figure out, why the sample code does not work?
This is in my toml file:
polars = "*"
This is the sample from Polars Eager cookbook:
use polars::prelude::*;
fn main() {
let s = Series::new("a", &[1, 2, 3]);
let ca =…

Robert
- 131
- 1
- 7
0
votes
2 answers
How to get logical AND to work on polars series
How do I get a logical AND between polar-series to work ..
With scalar it does ?!
My understanding is that ".and" will yield a boolean mask of element-wise AND of two series.
use polars::prelude::*;
fn main() {
let test_arr = [3, 5];
let…

Robert
- 131
- 1
- 7
0
votes
1 answer
How to access row elements in a polars LazyFrame/DataFrame
I struggle accessing the row-elements of a Frame.
One idea I have is to filter the dataframe down to a row, convert it to a vec or something similar and access the elements this way ?!
In Panadas I used to just use ".at / .loc / .iloc / etc."; with…

Robert
- 131
- 1
- 7
0
votes
1 answer
Peek at the next value in a rust-polars LazyFrame column while still working on the current one
I guess this is a conceptual oxymoron "peeking ahead in a LazyFrame-column" ... maybe one of you can enlighten me how to best do it.
I want to put the result of this for each date into a new column:
Ok( (next_weekday_number -…

Robert
- 131
- 1
- 7
0
votes
1 answer
How to iterate over two different Series/DataFrames and how to access a specific value based on an "index-column"
I am struggling with Rust Polars ...
In Pandas its fairly straight forward ... using Polars in Rust ... is another story;
Here is what I like to do (not working code):
use polars::prelude::*;
fn main() {
let days_data = df!("weekday" =>…

Robert
- 131
- 1
- 7
0
votes
1 answer
How to properly apply a MAP function
Need some help with a map function.
I want to take a DataType::Date and store the corresponding weekday as a string column.
I have it working starting with string -> date-type -> string (case #1).
What I am looking for is date-type -> string…

Robert
- 131
- 1
- 7
0
votes
0 answers
Return value of a trait
I want to implement a trait for shared behaviour among a set of models.
In particular, I have to be sure that every model implementing my trait have to be a function that returns a polars dataframe with (at least) some fixed columns.
For sake of…

Sigi
- 53
- 8
0
votes
1 answer
Lazy join multiple DataFrames on a Categorical
trying to implement the SAMPLE of Lazy join multiple DataFrames on a Categorical:
use polars::prelude::*;
fn lazy_example(mut df_a: LazyFrame, mut df_b: LazyFrame) -> Result {
let q1 = df_a.with_columns(vec
Robert
- 131
- 1
- 7
0
votes
1 answer
Applying function to Column
Is there a simple way to apply a function to a Polars DataFrame in Rust?
If my function and dataframe is the following for example:
fn double(x:i32) -> i32 {
x*2
}
let s0 = Series::new("id", &[1, 2, 3]);
let s1 = Series::new("cost", &[10, 20,…

Sam
- 773
- 4
- 13
0
votes
1 answer
Python Polars join on column with greater or equal
I have two polars dataframe, one dataframe df_1 with two columns start and end the other dataframe df_2 one with a column dates and I want to do a left join on df_2 under the condition that the dates column is in between the start and end column.
To…

alexp
- 697
- 4
- 9
0
votes
1 answer
Rust Polars - expected fn pointer, found opaque type
I am building a raku module to work with Rust Polars - via Rust ffi.
Generally it is working by passing opaque containers back and forth (SeriesC, ExprC and so on).
My first pass for the Expr .apply function looks like this (an extract):
use…

librasteve
- 6,832
- 8
- 30