Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How can I replace null values in polars with a prefix with ascending numbers?

I am trying to replace null values in my dataframe column by a prefix and ascending numbers(to make each unique).ie

name asset_number
Office Chair null
Office Chair null
Office Chair null
Office Chair CMP – 001
Office Chair CMP – 005
Office Chair null
Table null
Table CMP – 007

the null values should be replaced to something like PREFIX – 001,PREFIX – 002,…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

df = df.with_columns(
    pl.col("asset_number").fill_null(
        "PREFIX - " + pl.int_range(pl.len()).cast(pl.String)
    )
)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading