Numeric#
- class polars_extensions.numeric.NumericExtensionNamespace(expr: Expr)[source]#
Bases:
objectMethods
Convert Roman numerals to integers.
to_roman()Convert an integer to Roman numerals.
Convert Natural Language to Numbers
- from_roman() Expr[source]#
Convert Roman numerals to integers.
Examples
import polars_extensions as plx df = pl.DataFrame({"Roman": ['I', 'II', 'III', 'CCCIX', 'V']}) result = df.with_columns( pl.col('Roman').num_ext.from_roman().alias("Decoded") ) result
shape: (5, 2) ┌───────┬─────────┐ │ Roman ┆ Decoded │ │ --- ┆ --- │ │ str ┆ i64 │ ╞═══════╪═════════╡ │ I ┆ 1 │ │ II ┆ 2 │ │ III ┆ 3 │ │ CCCIX ┆ 309 │ │ V ┆ 5 │ └───────┴─────────┘
- to_roman() Expr[source]#
Convert an integer to Roman numerals.
Examples
import polars as pl import polars_extensions as plx df = pl.DataFrame({"numbers": [1, 2, 309, 4, 5]}) result = df.with_columns( pl.col('numbers').num_ext.to_roman().alias("Roman") ) result
shape: (5, 2) ┌─────────┬───────┐ │ numbers ┆ Roman │ │ --- ┆ --- │ │ i64 ┆ str │ ╞═════════╪═══════╡ │ 1 ┆ I │ │ 2 ┆ II │ │ 309 ┆ CCCIX │ │ 4 ┆ IV │ │ 5 ┆ V │ └─────────┴───────┘
- word_to_number() Expr[source]#
Convert Natural Language to Numbers
Examples
import polars as pl import polars_extensions as plx df = pl.DataFrame({"numbers": ['6', 'two', 'three hundred and nine', '5', '4']}) df.with_columns( pl.col('numbers').num_ext.word_to_number().alias("Actual Numbers") )
shape: (5, 2) ┌────────────────────────┬────────────────┐ │ numbers ┆ Actual Numbers │ │ --- ┆ --- │ │ str ┆ i64 │ ╞════════════════════════╪════════════════╡ │ 6 ┆ 6 │ │ two ┆ 2 │ │ three hundred and nine ┆ 309 │ │ 5 ┆ 5 │ │ 4 ┆ 4 │ └────────────────────────┴────────────────┘