Questions tagged [rust-polars]

271 questions
3
votes
1 answer

How can I groupby on the Year or Weekday of a date column in Polars Rust

I am trying to group a dataframe by year of the date column. First, let's create a dataframe: let s0 = Series::new("date", &["2021-01-14","2022-04-09","2021-06-24","2022-12-04","2022-11-25"]); let s1 = Series::new("values", &[1, 2, 3, 4, 5]); let…
ste_kwr
  • 820
  • 1
  • 5
  • 21
3
votes
0 answers

How to create Categorical from UInt32Type and RevMapping in Rust polars

I can get integer representation and revmap of CategoricalChunked. let s = Series::new("Fruit", ["Apple", "Apple", "Pear"]); let s_cat = s.cast(&DataType::Categorical(Some(Arc::new(RevMapping::default())))).unwrap(); let s_cat_chunck =…
Kushdesh
  • 1,118
  • 10
  • 16
3
votes
1 answer

What's the equivalent of `pandas.Series.map(json.loads)` in polars?

Based on the document of polars, one can use json_path_match to extract JSON fields into string series. But can we do something like pandas.Series.map(json.loads) to convert the whole JSON string at once? One can then further convert the loaded JSON…
Saddle Point
  • 3,074
  • 4
  • 23
  • 33
3
votes
1 answer

How can I share a lazy dataframe between different runtimes?

I have a desktop application where the majority of calculations (>90%) happen on the Rust side of it. But I want the user to be able to write scripts in Python that will operate on the df. Can this be done without serializing the dataframe between…
mainrs
  • 43
  • 3
3
votes
2 answers

Rust Polars: how to show all columns?

I use Rust Polars and found it's kind of hard to working with it since not quite sure how to show all the columns. use polars::df; // use macro let df = df! [ "Column A 12345678910" => ["a", "b", "c"], "Column B 12345678910" => [1, 2, 3], …
weiz
  • 91
  • 2
  • 6
3
votes
1 answer

How to add a conditional computed col to polars dataframe in rust?

df1 has ['a', 'b', 'c'] 3 cols, I want to get a df2 with 4 cols of ['a', 'b', 'c', 'd']. And d is computed like this: if a>5 { d = b + c } else if a<-5 { d = c - b + a } else { d = 3.0 * a } How can I do this with polars in rust? maybe for…
tempbottle
  • 33
  • 4
3
votes
2 answers

Rust: DataFrame in polars using a vector of structs

Problem I want to read in data into polars dataframe from mysql database. I am using sqlx. sqlx generates a vector of Structs for example: Vec below: From sqlx Docs: // no traits are needed struct Country { country: String, count: i64…
Hamza Zubair
  • 1,232
  • 13
  • 21
2
votes
1 answer

I'm using Polars with ConnectorX: why do I get Dataframe type error

I'm trying to get the table description from a Postgres database. I use ConnectorX with Arrow2 destination and I'm trying to store it in a Polars Dataframe. Here's the connection definition: use connectorx::prelude::*; use polars_core; use…
2
votes
1 answer

How to create a new column based on the common start word between two series in a Polars DataFrame?

I have a Polars DataFrame consisting of two series, 'foo' and 'bar', which contain lists of integers. I want to create a new column that assigns a value of 1 if the start word (first element) of the 'foo' series is equal to the start word of the…
tikendraw
  • 451
  • 3
  • 12
2
votes
1 answer

How do I transform multiple columns simultaneously in polars dataframe?

I have two dataframes, one of them is just a single row, and I would like to transform each of the columns in the first one with the values in the single row in some fashion. How do I do this? Here's what I want to achieve: df1 = pl.DataFrame({'c1':…
ste_kwr
  • 820
  • 1
  • 5
  • 21
2
votes
1 answer

unable to use .col() method in polars rust

i am trying to execute this line in my rust programme: let filtered_df = df.filter(col("time").eq(cursor_date_str)).head(Some(1)); and the compiler returns that error[E0425]: cannot find function `col` in this scope --> src/main.rs:50:37 | 50…
Arthur Zhang
  • 107
  • 8
2
votes
1 answer

How can I apply a custom function and return named fields (Struct) in Rust Polars

Below is a simple example of a groupby-agg operation where I want to return an array/vector of min and max values of each group as a single column in the result. #[pyfunction] fn test_fn(pydf: PyDataFrame, colnm: &str, by_cols: Vec<&str>) ->…
lebesgue
  • 837
  • 4
  • 13
2
votes
0 answers

How do I access the time bounds of a temporal groupby in the aggregation expression context?

I am trying to compute various statistics on groups of timeseries data using the duration of the points (time until the next point). I would like the duration of the last point in a group to be the time until the boundary of the group. Crucially I…
2
votes
0 answers

Polars conversion error going from Python to Rust with pyo3

Related to the solution proposed in this other question. This code creates a polars dataframe of python dictionaries. In Python land, everything is fine. The code fails when we extract to Rust land. use pyo3::prelude::*; use pyo3_polars::*; let…
GrantS
  • 781
  • 7
  • 16
2
votes
1 answer

Create new Series from existing Series and map values

My use case: I have a column with wild time stamps (strings) and I want to parse them into a timestamp type. The docs mention ChunkedArray to be the typed container for my strings. However, I cannot complete the picture. fn with_timestamps(mut df:…
user4344
  • 193
  • 1
  • 10
1 2
3
18 19