I am trying to account for a zero in the denominator when calculating a normalized percentage deviation from the term in the denominator.
Here is the code snippet -
let out: DataFrame = input_df
.lazy()
.with_columns(vec![
when(col("write") == lit(0.0) && result.wr == 0.0)
.then(lit(0.0))
.otherwise((lit(result.wr) - col("write")) / col("write") * lit(100))
.alias("write%"),
])
.collect()
.unwrap();
The problem is col("write") == lit(0.0)
resolves to false
even when the respective element in col("write")
is 0.0
. I'm unclear why or how to solve it.
col("write")
is of type f64
, so is result.wr
.
I tried changing to just lit(0)
which yielded the same result. Not using lit()
throws a 'Expected Expr' error.