Эквивалент Polars для приведения строк, таких как Pandas to_numeric ⇐ Python

Программы на Python
Anonymous
Эквивалент Polars для приведения строк, таких как Pandas to_numeric

Сообщение Anonymous »

При применении pandas.to_numeric() возвращаемый dtype имеет значение float64 или int64 в зависимости от предоставленных данных.
Есть ли эквивалент для этого в полярах?
import pandas as pd
import polars as pl

df = pl.from_repr("""
┌──────┬──────┐
│ col1 ┆ col2 │
│ --- ┆ --- │
│ str ┆ str │
╞══════╪══════╡
│ 1 ┆ 3.5 │
│ 2 ┆ 4.6 │
└──────┴──────┘
""")

pl.from_pandas(df.to_pandas().apply(pd.to_numeric))
# shape: (2, 2)
# ┌──────┬──────┐
# │ col1 ┆ col2 │
# │ --- ┆ --- │
# │ i64 ┆ f64 │
# ╞══════╪══════╡
# │ 1 ┆ 3.5 │
# │ 2 ┆ 4.6 │
# └──────┴──────┘


Подробнее здесь: https://stackoverflow.com/questions/737 ... to-numeric

Вернуться в «Python»