Код: Выделить всё
df = (
pl.DataFrame({"animal": ['elephant', 'dog', 'cat', 'mouse'],
"country": ['Mexico', 'Denmark', 'Mexico', 'France'],
"cost": [1000.0, 20.0, 10.0, 120.0]})
)
print(df)
shape: (4, 3)
┌──────────┬─────────┬────────┐
│ animal ┆ country ┆ cost │
│ --- ┆ --- ┆ --- │
│ str ┆ str ┆ f64 │
╞══════════╪═════════╪════════╡
│ elephant ┆ Mexico ┆ 1000.0 │
│ dog ┆ Denmark ┆ 20.0 │
│ cat ┆ Mexico ┆ 10.0 │
│ mouse ┆ France ┆ 120.0 │
└──────────┴─────────┴────────┘
Код: Выделить всё
shape: (4, 5)
┌──────────┬─────────┬────────┬────────────────┬─────────────────┐
│ animal ┆ country ┆ cost ┆ animal_encoded ┆ country_encoded │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ f64 ┆ i64 ┆ i64 │
╞══════════╪═════════╪════════╪════════════════╪═════════════════╡
│ elephant ┆ Mexico ┆ 1000.0 ┆ 0 ┆ 0 │
│ dog ┆ Denmark ┆ 20.0 ┆ 1 ┆ 1 │
│ cat ┆ Mexico ┆ 10.0 ┆ 2 ┆ 0 │
│ mouse ┆ France ┆ 120.0 ┆ 3 ┆ 2 │
└──────────┴─────────┴────────┴────────────────┴─────────────────┘
Подробнее здесь: https://stackoverflow.com/questions/765 ... -on-polars
Мобильная версия