I am trying to add another column that will contain combination of two columns (Total & percentage) into a result column(labels_value) which look like: (Total) percentage%.
Basically to wrap bracket strings on Total column and add % string at the end of combination of these two columns.
import polars as pl
pl.Config(tbl_rows=21) # increase repr defaults
so_df = pl.from_repr("""
┌──────────────┬─────────────────────┬─────┬───────┬────────────┬────────┐
│ Flag ┆ Category ┆ len ┆ Total ┆ percentage ┆ value │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ i64 ┆ i64 ┆ f64 ┆ f64 │
╞══════════════╪═════════════════════╪═════╪═══════╪════════════╪════════╡
│ Outof Range ┆ Thyroid ┆ 7 ┆ 21 ┆ 33.33 ┆ 33.33 │
│ Outof Range ┆ Inflammatory Marker ┆ 2 ┆ 8 ┆ 25.0 ┆ 25.0 │
│ Outof Range ┆ Lipid ┆ 12 ┆ 63 ┆ 19.05 ┆ 19.05 │
│ Outof Range ┆ LFT ┆ 14 ┆ 87 ┆ 16.09 ┆ 16.09 │
│ Outof Range ┆ DLC ┆ 11 ┆ 126 ┆ 8.73 ┆ 8.73 │
│ Outof Range ┆ Vitamin ┆ 1 ┆ 14 ┆ 7.14 ┆ 7.14 │
│ Outof Range ┆ CBC ┆ 2 ┆ 45 ┆ 4.44 ┆ 4.44 │
│ Outof Range ┆ KFT ┆ 2 ┆ 56 ┆ 3.57 ┆ 3.57 │
│ Outof Range ┆ Urine Examination ┆ 1 ┆ 28 ┆ 3.57 ┆ 3.57 │
│ Within Range ┆ Thyroid ┆ 14 ┆ 21 ┆ 66.67 ┆ -66.67 │
│ Within Range ┆ Inflammatory Marker ┆ 6 ┆ 8 ┆ 75.0 ┆ -75.0 │
│ Within Range ┆ Lipid ┆ 51 ┆ 63 ┆ 80.95 ┆ -80.95 │
│ Within Range ┆ LFT ┆ 73 ┆ 87 ┆ 83.91 ┆ -83.91 │
│ Within Range ┆ DLC ┆ 115 ┆ 126 ┆ 91.27 ┆ -91.27 │
│ Within Range ┆ Vitamin ┆ 13 ┆ 14 ┆ 92.86 ┆ -92.86 │
│ Within Range ┆ CBC ┆ 43 ┆ 45 ┆ 95.56 ┆ -95.56 │
│ Within Range ┆ KFT ┆ 54 ┆ 56 ┆ 96.43 ┆ -96.43 │
│ Within Range ┆ Urine Examination ┆ 27 ┆ 28 ┆ 96.43 ┆ -96.43 │
│ Within Range ┆ Anemia ┆ 38 ┆ 38 ┆ 100.0 ┆ -100.0 │
│ Within Range ┆ Diabetes ┆ 22 ┆ 22 ┆ 100.0 ┆ -100.0 │
│ Within Range ┆ Electrolyte ┆ 46 ┆ 46 ┆ 100.0 ┆ -100.0 │
└──────────────┴─────────────────────┴─────┴───────┴────────────┴────────┘
""")
I have tried below three ways and none of them worked:
(so_df
# .with_columns(labels_value = "("+str(pl.col("Total"))+") "+str(pl.col("percentage"))+"%")
# .with_columns(labels_value = "".join(["(",str(pl.col("Total")),") ",str(pl.col("percentage")),"%"]))
# .with_columns(labels_value =pl.concat_str([pl.col("Total"),pl.col("percentage")])))
Desired result would be to add a new column like:
┌──────────────┐
│ labels_value │
│ --- │
│ str │
╞══════════════╡
│ (21) 33.33% │
│ (8) 25% │
│ (63) 19.05% │
│ (87) 16.09% │
│ (126) 8.73% │
│ … │