Есть ли предпочтительный способ зацикливания и применения функций к столбцам Polars?
Вот пример того, что я пытаюсь сделать в pandas:
import polars as pl
df1 = pl.DataFrame(
{
"A": np.random.rand(10),
"B": np.random.rand(10),
"C": np.random.rand(10)
}
)
df2 = pl.DataFrame(
{
"X1": np.random.rand(10),
"X2": np.random.rand(10),
"X3": np.random.rand(10)
}
)
# pandas code
# this is just a weighted sum of df2, where the weights are from df1
df1.to_pandas().apply(
lambda weights: df2.to_pandas().mul(weights, axis=0).sum() / weights.sum(), axis=0,
result_type='expand'
)
A B C
X1 0.647355 0.705358 0.692214
X2 0.500439 0.416325 0.384294
X3 0.601890 0.606301 0.577076
Подробнее здесь: https://stackoverflow.com/questions/755 ... formations