Questions tagged [rust-polars]
271 questions
0
votes
1 answer
Does `DataFrame.groupby*` in polars preserves the original order of rows within each group?
The doc mentions that there are parameters to make groups maintain the original order. However, it is not clear on whether the original order of rows are preserved within each group.

Benjamin Du
- 1,391
- 1
- 17
- 25
0
votes
1 answer
Rust cannot borrow `var` as mutable, as it is behind a `&` reference using zip
The code is:
fn iter_and_make_feature_dataframe(df: &DataFrame) {
// iter over rows
// let columns = columns.unwrap_or(vec![]);
let col_len = df.shape().1;
let columns = df.get_column_names();
let mut df = df.clone();
…

Crispy13
- 230
- 1
- 3
- 16
0
votes
1 answer
unable to convert json to polars dataframe,'read an Array from a non-Array JSON''
i am struggling with conversion from JSON(deserialised from API-provicded data) to polars dataframe.
below are my structs and defined function:
// structs for option price query
#[derive(Serialize, Deserialize, Debug)]
pub struct OptionResponse {
…

Arthur Zhang
- 107
- 8
0
votes
1 answer
Use multiple columns in list expression
I want to do a search sorted between the lists in column a and b:
import polars as pl
df = pl.DataFrame(
{
"a": [[1, 2, 3], [8, 9]],
"b": [[2], [10, 6]]
}
)
print(df)
res = df.lazy().with_columns(
[
…

The Unfun Cat
- 29,987
- 31
- 114
- 156
0
votes
1 answer
Rust Polars - Selecting columns after applying filter (on rows) of a DataFrame
This used to be working until upgraded to latest Polars. The df Dataframe has more than 2 columns, CP and CP are 2 of them. The intent here is to select column CK and CP for rows that are greater than value 0.
let e11_filter = df
.lazy()
…

humphreylee
- 3
- 3
0
votes
2 answers
how to covert a whole column of date strings to integers
i have a dataframe that look like this
i would like to convert the first column 'time' with date strings into a column with only numbers in format of "YYYYMMDD"(e.g.: 20230531) in u64.
i tried building up a function to do this but i am struggling…

Arthur Zhang
- 107
- 8
0
votes
1 answer
remove duplicates in polars rust
hi i am trying to remove duplicates based on a column "time" in my dataframe.
i read the official document which defines the unique() method as follows:
pub fn unique(
&self,
subset: Option<&[String]>,
keep: UniqueKeepStrategy,
…

Arthur Zhang
- 107
- 8
0
votes
1 answer
How to extract the value from nested list value?
Given an aggregated dataframe and an index dataframe, how to extract data from the list[<>]?
┌──────┬────────────┬───────────┐
│ read ┆ region ┆ cov │
│ --- ┆ --- ┆ --- │
│ str ┆ list[str] ┆ list[i32]…

ihsagihok
- 3
- 1
0
votes
1 answer
How do I repeat each row in a polars dataframe a particular number of times?
let mut df = df! (
"start" => &[6, 3, 1],
"end" => &[7, 4, 2],
"repeats" => &[1, 0, 2],
)?.sort(["start", "end"], false)?;
How do I repeat each row by the number given in the repeats column?
Here is an example attempt:
df.with_column(
…

The Unfun Cat
- 29,987
- 31
- 114
- 156
0
votes
1 answer
How do I get a column of a dataframe as a series
I have the following code:
use polars::prelude::*;
use polars_lazy::prelude::*;
pub fn main() -> Result<(), PolarsError> {
let df = df! (
"start" => &[3, 8, 5],
"end" => &[6, 9, 7],
"idx" => &[0, 1, 2],
)?;
}
How do…

The Unfun Cat
- 29,987
- 31
- 114
- 156
0
votes
1 answer
Filtering with polars in Rust - Eagerly
I'm trying to do a simple filter with polars in rust :
let mask = df.column("AISLE_ID").unwrap().eq(lit(1));
let filtered_df = df.filter(&mask).unwrap();
But it's not working at all : expected &ChunkedArray<...>, found &bool
I can do it with lazy…

Developppeur
- 39
- 1
- 7
0
votes
0 answers
Lazyframe with streaming panicked at 'assertion failed: buf.is_empty()
I'm currently trying to exec the code bellow and receiving a strange error.
Join sample
let mut person_schema = Schema::new();
person_schema.with_column("name".parse().unwrap(), DataType::Utf8);
…

Don
- 101
- 2
0
votes
0 answers
How to do proper conversion from Polars Dataframe to Smartcore Densematrix in rust
So i have been playing around with polars and smartcore but i have some trouble with converting from a Dataframe into a DenseMatrix.
In my code I'm reading in some simple csv data consisting of several columns containing numeric data.
This gets read…

Toerktumlare
- 12,548
- 3
- 35
- 54
0
votes
1 answer
Polars Join cleverly infer appropriate dtypes of join key?
In pl.join(), Is there any syntax sugar to "cleverly" cast the dtype of join cols. e.g. the higher granularity option or just take the dtypes from df1? could we add it as optional param to pl.join()?
e.g. int32 -> int64, datetime[ms] ->…

user1441053
- 680
- 1
- 5
- 10
0
votes
1 answer
Rust polars Series::series_equal method asserts even if incorrect
My test asserts true, even though I have different values in the Series.
In the below test index 0 (100.94947) is wrong but it passes
pub fn convert_tb_to_tib(s: Series) -> Series {
let result = s.cast(&DataType::Float64).unwrap() *…

NotABot83
- 7
- 1