I am using polars sql_expr() for evaluating the dataframe and while evaluating the result found that sql_expr is giving incorrect output for a simple calculation like "2+4/5".
for example:
polars dataframe:
col1 | col2 | col3 |
---|---|---|
jan-23 | 2 | 5 |
feb-23 | 2 | 4 |
expected result:
col1 | col2 | col3 | result |
---|---|---|---|
jan-23 | 2 | 5 | 3.0000 |
feb-23 | 2 | 4 | 2.8000 |
output obtained:
col1 | col2 | col3 | result |
---|---|---|---|
jan-23 | 2 | 5 | 3.0000 |
feb-23 | 2 | 4 | 2.0000 |
df = pl.DataFrame("col1":["jan-23", "feb-23"],"col2":[2,2], "col3:[5,4])
formula_rhs = "col2 + col3 / 5"
col_name ="result"
df.with_columns(pl.sql_expr(formula_rhs).alias(col_name).cast(pl.Float64))
also changed pl.Float64 to pl.Decimal.