Questions tagged [rust-polars]

271 questions
10
votes
1 answer

Rust Polars - get a struct Series from df.column instead of an '&' reference

I am building an interface from Raku NativeCall to Rust Polars to get that cool Arrow2 performance boost. At the high level I would like to work with Polars structs such as DataFrame and Series as attributes of matching containers. So to do…
librasteve
  • 6,832
  • 8
  • 30
7
votes
2 answers

Extracting a Rust Polars dataframe value as a scalar value

I have the following code to find the mean of the ages in the dataframe. let df = df! [ "name" => ["panda", "polarbear", "seahorse"], "age" => [5, 7, 1], ].unwrap(); let mean = df .lazy() .select([col("age").mean()]) …
xosxos
  • 167
  • 1
  • 6
6
votes
2 answers

Creating Polars Dataframe from Vec

Supposing I have a vector of structs like so: struct Test { id:u32, amount:u32 } fn main() { let test_vec:Vec = vec![Test{id:1,amount:3}, Test{id:3,amount:4}]; } Is there a way to get this into a polars dataframe with the…
Sam
  • 773
  • 4
  • 13
6
votes
1 answer

lazy() method not found in `polars::prelude::DataFrame`

I am writing an extern lib for Polars in Rust (for consumption by Raku::Dan) and would like to get out an opaque container for a LazyFrame object by calling df.lazy(). use polars::prelude::*;//{CsvReader, DataType, DataFrame, Series}; use…
librasteve
  • 6,832
  • 8
  • 30
6
votes
1 answer

Iterate over rows polars rust

I am trying to iterate over each row of a Polars rust dataframe. In this endeavour, I have found df.get but the documentation says that this is slow. Then I have tried df.column("col").get but this seems to pose similar problems. What is the correct…
rhobro
  • 103
  • 1
  • 7
6
votes
1 answer

Thread creation on function return in Rust WASM

I am working with Polars in a wasm environment. I have noticed an inconsistency with the LazyFrame.collect operation where it sometimes creates threads when working with certain datasets. Here is the code that relates to the…
Kival M
  • 182
  • 1
  • 10
5
votes
1 answer

How to use date in polars in rust?

I am reading file using LazyCsvReader and the file contains a date column. LazyCsvReader read the date as string. The date is in format "%m-%d-%Y". How to properly handle it as date. There is a page for this but it is for python. I tried to read the…
Kushdesh
  • 1,118
  • 10
  • 16
5
votes
2 answers

Writing expression in polars-lazy in rust

I need to write my own expression in polars_lazy. Based on my understanding from the source code I need to write a function that returns Expr::Function. The problem is that in order to construct an object of this type, an object of type…
dkla
  • 51
  • 1
4
votes
2 answers

How to reliably concatenate LazyFrames in Rust Polars

Cargo.toml: [dependencies] polars = { version = "0.27.2", features = ["lazy"] } I would expect that any two LazyFrames could be vertically concatenated as long as the columns they have in common had the same or promotable dtypes, with missing…
BallpointBen
  • 9,406
  • 1
  • 32
  • 62
4
votes
1 answer

Add column/series to dataframe in polars rust

I had a hard time finding the answer for such simple question. I was stuck at trying to use "append", "extend" or other methods. Finally I found/realized that the with_column method is the way to go in polars. I figure that I should put out my…
nklsla
  • 315
  • 1
  • 9
4
votes
1 answer

polars native way to convert unix timestamp to date

I'm working with some data frames that contain Unix epochs in ms, and would like to display the entire timestamp series as a date. Unfortunately, the docs did not help me find a polars native way to do this, and I'm reaching out here. Solutions on…
tenxsoydev
  • 370
  • 2
  • 10
4
votes
0 answers

How does Polars' global string cache work?

I am trying to replace the null values in a polars categorical series with another literal string. The solution I had worked in an older version of polars before categoricals started using the global string cache by default. let data =…
Kival M
  • 182
  • 1
  • 10
4
votes
0 answers

How to get date element when iterating over DateChunked in polars rust

I want to iterate over DateChunked using map and use the date element. But iterating over gives me i32. How I can use date? Running below code complains. use polars::export::chrono::{NaiveDate}; fn main() { let df = df! [ "date_series"…
Kushdesh
  • 1,118
  • 10
  • 16
4
votes
2 answers

Fast apply of a function to Polars Dataframe

What are the fastest ways to apply functions to polars DataFrames - pl.DataFrame or pl.internals.lazy_frame.LazyFrame? This question is piggy-backing off Apply Function to all columns of a Polars-DataFrame I am trying to concat all columns and hash…
Jenobi
  • 368
  • 4
  • 12
4
votes
1 answer

How to perform computations easily between every column in a polars DataFrame and the mean of that column

Environment macos: monterey node: v18.1.0 nodejs-polars: 0.5.3 Goal Subtract every column in a polars DataFrame with the mean of that column. Pandas solution In pandas the solution is very concise thanks to…
1
2 3
18 19