Код: Выделить всё
import polars as pl
import numpy as np
import string
rng = np.random.default_rng(42)
nr = 3
letters = list(string.ascii_letters)
uppercase = list(string.ascii_uppercase)
words, groups = [], []
for i in range(nr):
word = ''.join([rng.choice(letters) for _ in range(rng.integers(3, 20))])
words.append(word)
group = rng.choice(uppercase)
groups.append(group)
df = pl.DataFrame(
{
"a_0": np.linspace(0, 1, nr),
"a_1": np.linspace(1, 2, nr),
"a_2": np.linspace(2, 3, nr),
"b_0": np.random.rand(nr),
"b_1": 2 * np.random.rand(nr),
"b_2": 3 * np.random.rand(nr),
"words": words,
"groups": groups,
}
)
print(df)
shape: (3, 8)
┌─────┬─────┬─────┬──────────┬──────────┬──────────┬─────────────────┬────────┐
│ a_0 ┆ a_1 ┆ a_2 ┆ b_0 ┆ b_1 ┆ b_2 ┆ words ┆ groups │
│ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- ┆ --- │
│ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ f64 ┆ str ┆ str │
╞═════╪═════╪═════╪══════════╪══════════╪══════════╪═════════════════╪════════╡
│ 0.0 ┆ 1.0 ┆ 2.0 ┆ 0.653892 ┆ 0.234362 ┆ 0.880558 ┆ OIww ┆ W │
│ 0.5 ┆ 1.5 ┆ 2.5 ┆ 0.408888 ┆ 0.213767 ┆ 1.833025 ┆ KkeB ┆ Z │
│ 1.0 ┆ 2.0 ┆ 3.0 ┆ 0.423949 ┆ 0.646378 ┆ 0.116173 ┆ NLOAgRxAtjWOHuQ ┆ O │
└─────┴─────┴─────┴──────────┴──────────┴──────────┴─────────────────┴────────┘
Код: Выделить всё
m=3Код: Выделить всё
shape: (9, 4)
┌─────────────────┬────────┬─────┬──────────┐
│ words ┆ groups ┆ a ┆ b │
│ --- ┆ --- ┆ --- ┆ --- │
│ str ┆ str ┆ f64 ┆ f64 │
╞═════════════════╪════════╪═════╪══════════╡
│ OIww ┆ W ┆ 0.0 ┆ 0.653892 │
│ KkeB ┆ Z ┆ 0.5 ┆ 0.408888 │
│ NLOAgRxAtjWOHuQ ┆ O ┆ 1.0 ┆ 0.423949 │
│ OIww ┆ W ┆ 1.0 ┆ 0.234362 │
│ KkeB ┆ Z ┆ 1.5 ┆ 0.213767 │
│ NLOAgRxAtjWOHuQ ┆ O ┆ 2.0 ┆ 0.646378 │
│ OIww ┆ W ┆ 2.0 ┆ 0.880558 │
│ KkeB ┆ Z ┆ 2.5 ┆ 1.833025 │
│ NLOAgRxAtjWOHuQ ┆ O ┆ 3.0 ┆ 0.116173 │
└─────────────────┴────────┴─────┴──────────┘
Подробнее здесь: https://stackoverflow.com/questions/779 ... the-others