我想过滤一个Polars DataFrame,然后获取行数。
我现在所做的似乎是工作,但感觉如此错误:
let item_count = item_df
.lazy()
.filter(not(col("status").is_in(lit(filter))))
.collect()?
.shape().0;
在随后的DataFrame操作中,我需要在除法操作中使用此
.with_column(
col("count")
.div(lit(item_count as f64))
.mul(lit(100.0))
.alias("percentage"),
);
这是一个很小的数据集(几十行),所以我不担心性能,但我想知道最好的方法是什么。
2条答案
按热度按时间luaexgnf1#
虽然
LazyFrame
上似乎没有预定义的方法,但您可以使用polars表达式:pqwbnv8z2#
与_row_count一起使用:
输出量: