Questions tagged [rust-polars]

271 questions
1
vote
1 answer

rust polars convert string column to datetime

I'm trying to learn rust and using polars. I've a simple CSV file names,pdate,orders alice,2023-02-12,2 alice,2023-02-18,1 alice,2023-02-22,6 bob,2022-12-10,1 bob,2022-12-14,1 bob,2022-12-30,4 I read it in using let mut df =…
broccoli
  • 4,738
  • 10
  • 42
  • 54
1
vote
1 answer

Add a new Date column based off an existing Date column in rust polars

I am trying to add a new column in my polars DataFrame: 'for_date' There is already a column named 'made_on', and I want 'for_date' to be 1 day greater than 'made_on'. So if 'made_on' is 2022-12-25 then for_date should be 2022-12-26 etc. My df looks…
kykyi
  • 375
  • 4
  • 10
1
vote
1 answer

Fast way to concatenate two string columns in Rust Polars?

I am currently concatenating two series in Polars like this: df.with_column(Series::new( "C", &(df.column("A").unwrap() + &Series::new("", (0..df.shape().0).map(|_| "_").collect::>())) +…
Jage
  • 453
  • 2
  • 9
1
vote
2 answers

Is it possible to subtract a list column?

I want to operate this expression with data. But it gives the error that List(float64) type doesn't have the operation. I guess the list type isn't implemented element-wise operations. (col("vec").last() - col("vec")).abs().sum() vec …
1
vote
1 answer

how to change datetime series to date series?

let datetime = frame.column("datetime_nano")?.cast(&DataType::Datetime(TimeUnit::Nanoseconds, None))?; let date = datetime.cast(&DataType::Date)?; let time = datetime.cast(&DataType::Time)?; println!("{}", datetime); println!("{}", date); The date…
somewheve
  • 125
  • 6
1
vote
0 answers

How do I convert a Polars DataFrame to Vec?

edit: To hopefully be more concise, how do I do this?- use polars::prelude::{DataFrame, NamedFrom, df}; use arrow::record_batch::RecordBatch; fn main() { let polars_df: DataFrame = df!("cat_data" => &[1.0, 2.0, 3.0, 4.0], …
1
vote
1 answer

Rust-polars: how can I pass the "other" parameter for the function "is_in" by reference?

I am very new to Rust so please excuse me if this is a trivial question. I am trying to filter a dataframe as follows: let allowed = Series::from_iter(vec![ "string1".to_string(), "string2".to_string(), ]); let df =…
1
vote
1 answer

How do I read multiple CSV/Parquet/JSON etc files from a directory using Rust?

I am using polars with Rust and I would like to be able to read multiple csv files as input. I found this section in the documentation that shows how to use glob patterns to read multiple files using Python, but I could not find a way to do this in…
Finlay Weber
  • 2,989
  • 3
  • 17
  • 37
1
vote
1 answer

Filter a polars dataframe by date in rust

Im trying to filter a dataframe by date. But filter it with expressions like this would be really cumbersome for a date like "2019-11-01 10:15:00". My goal is to do something like the python version: use polars::export::chrono::NaiveDateTime; use…
nklsla
  • 315
  • 1
  • 9
1
vote
0 answers

Sending polars Dataframe via juniper GraphQL

I am trying to send the Polars dataframe over juniper GraphQL, but #[juniper::graphql_object] is complaining about trail bound the trait bound `Result, FieldError>: IntoResolvable<'_, __S, _,…
921kiyo
  • 584
  • 4
  • 14
1
vote
1 answer

Efficient way to update a single element of a Polars DataFrame?

Polars DataFrame does not provide a method to update the value of a single cell currently. Instead, we have to the method DataFrame.apply or DataFrame.apply_at_idx that updates a whole column / Series. This can be very expensive in situations where…
Benjamin Du
  • 1,391
  • 1
  • 17
  • 25
1
vote
1 answer

How do I pivot a table using Rust Polars?

How do I create a pivoted dataframe with polars (in Rust), where I can both specify indices and columns? For indices I want the groups and for the columns I want aggregated calculations per month, and year. like this, ish: df = pd.DataFrame({ …
Ynax
  • 59
  • 4
1
vote
1 answer

Filter by hour of datetime in rust polars

How can I filter a dataframe by the hour of a date column? let df = df.lazy().select([ col("value").filter( col("date").dt().hour().gt(7).lt(20) ).alias("hours").sum(), ]).collect()?; Whith that I get an Error Error: Invalid operation…
Brucie Alpha
  • 1,135
  • 2
  • 12
  • 31
1
vote
2 answers

Compare two Pola-rs dataframes by position

Suppose I have two dataframes like: let df_1 = df! { "1" => [1, 2, 2, 3, 4, 3], "2" => [1, 4, 2, 3, 4, 3], "3" => [1, 2, 6, 3, 4, 3], } .unwrap(); let mut df_2 = df_1.clone(); …
baarkerlounger
  • 1,217
  • 8
  • 40
  • 57
1
vote
0 answers

Polars: how to create a dataframe from arrow RecordBatch?

I am using rust arrow library and have a RecordBatch struct. I want to create a Polars dataframe out it, do some operations in the Polars land, and move the result back to RecordBatch. Since both are arrow based, I suppose there might be an…
Nikhil Garg
  • 3,944
  • 9
  • 30
  • 37