Questions tagged [rust-polars]

271 questions
0
votes
1 answer

Rust Polars filter string input eagerly

I am trying to understand the 2 modes (lazy, eager) in Polars. I Found a way to do this lazily: let out = df .lazy() .select([col("A"), col("B") .filter(col("B").str().contains(input))]) .collect() …
fvg
  • 153
  • 3
  • 9
0
votes
1 answer

Polars with_context filter

I'm having a hard time understanding how to use the lazy with_context. The docs say This allows expressions to also access columns from DataFrames that are not part of this one. I want to filter a column based on a column from another frame, but I…
Cory Grinstead
  • 511
  • 3
  • 16
0
votes
0 answers

Moved value of an expression in match statement

I'm generating and expression from a string. Let us suppose to have a data frame with a close column ant I'm trying to compute all in parallel through expressions. If the function receives a string "rolling_mean" I need to compute close -…
Sigi
  • 53
  • 8
0
votes
1 answer

How to convert a AnyValue::Datetime into a chrono Timestamp

I have use Polars in my Cargo.toml like this: polars = { version = "0.24.3", features = ["lazy", "temporal", "ipc", "ipc_streaming", "dtype-datetime"] } I have a Series extracted from a DataFrame that has datetime[ns] without a timezone. I now…
SirVer
  • 1,397
  • 1
  • 16
  • 15
0
votes
1 answer

Can I use indexing [start:end] in expressions instead of offset and length in polars

In Exp.slice, the only supported syntax is exp.slice(offset,length), but in some cases, something like exp[start:end] would be more convenient and consistent. So how to write exp[1:6] for exp.slice(1,5) just like it in pandas?
Facet
  • 53
  • 6
0
votes
1 answer

How to get an item in a polars dataframe column and put it back into the same column at a different location

Still new to polars and rust ... so here is a nooby question: How do I access a value within a DataFrame at a specific location. How do I overwrite a value within a DataFrame at a specific location. Here is a NON-WORKING code: use…
Robert
  • 131
  • 1
  • 7
0
votes
1 answer

How to pass variable from one method to another in impl (in Rust)

Specific Question I need to pass csv variable from load_csv function to operations function. Code use polars::{ prelude::{CsvReader, SerReader}, frame::DataFrame, error::PolarsResult }; struct Boilerplate {} impl Boilerplate { fn…
S3emingly
  • 15
  • 5
0
votes
0 answers

How to process a column of list_items

I have a DataFrame with a ListType column. Now I am trying to find a way to process each list within that column. If I could convert the list to a vector (ideally without unpacking the list and then re-packing it into a vector ... is there such a…
Robert
  • 131
  • 1
  • 7
0
votes
0 answers

How to use a groupby_column_item in alias naming of a new column?

Trying to find out if there is a way to use a groupby column in naming an alias after an aggregate: Could not find anything here on SO / Reddit etc. Could I use an EXPR in the alias function? Thanks for any help :) use polars::prelude::*; fn main()…
Robert
  • 131
  • 1
  • 7
0
votes
2 answers

How to merge two DataFrames with different columns / sizes

Looking for a way to combine two DataFrames. df1: shape: (2, 2) ┌────────┬──────────────────────┐ │ Fruit ┆ Phosphorus (mg/100g) │ │ --- ┆ --- │ │ str ┆ i32 │ ╞════════╪══════════════════════╡ │ Apple ┆ 11 …
Robert
  • 131
  • 1
  • 7
0
votes
1 answer

How do I serialize Polars DataFrame Row/HashMap of `AnyValue` into JSON?

I have a row of a polars dataframe created using iterators reading a parquet file from this method: Iterate over rows polars rust I have constructed a HashMap that represents an individual row and I would like to now convert that row into JSON. This…
Al Johri
  • 1,729
  • 22
  • 23
0
votes
0 answers

How to implement frame_equal_missing with tolerance (like pandas)?

assert!(expected.frame_equal_missing(&res1)); is failing when using pct_change. because of float rounding differences (a-b)/b can be different from a/b - 1 How can I frame_equal_missing with a tolerance like pandas? let df = df! [ "A" …
MBr
  • 3
  • 4
0
votes
4 answers

Combine different values of multiple columns into one column

Need help to "translate" a python example to rust. The python example was given here Here is the code snippet I try to make work: use polars::prelude::*; fn main() { let s1 = Series::new("Fruit", &["Apple", "Apple", "Pear"]); let s2 =…
Robert
  • 131
  • 1
  • 7
0
votes
1 answer

How to create a polars-Series from a vector of options

I am a little confused. Creating a polars series with a vector of "simple" options Vec> works ... but a vector of options with complex values (e.g. vectors / arrays) does not?! Vec>> Why? ... and how to make it work? use…
Robert
  • 131
  • 1
  • 7
0
votes
1 answer

How to convert rows into columns given an arbitrary step size in polars (in a single step)?

I've managed to solve this problem in two steps. import polars as pl text = "a brown fox jumps over a lazy dog's head" step = 3 df = pl.DataFrame({"a":text.split(" ")}) first = df.filter(pl.arange(0, pl.count())%step==0) second =…
pedrosaurio
  • 4,708
  • 11
  • 39
  • 53