Code: Select all
pl.DataFrame({
'A': ['a0', 'a0', 'a1', 'a1'],
'B': ['b1', 'b2', 'b1', 'b2'],
'x': [0, 10, 5, 1]
})
< /code>
Ich möchte den Wert von Spalte B
Ich weiß, dass es eine Lösung mit pl.Expr.get() und pl.Expr.arg_max() gibt, aber ich wollte pl.Expr.top_k_by( verwenden ) stattdessen, und aus irgendeinem Grund funktioniert es bei mir nicht damit k = 1:
Code: Select all
df.with_columns(
pl.col.B.top_k_by("x", 1).over("A").alias("y")
)
< /code>
ComputeError: the length of the window expression did not match that of the group
Error originated in expression: 'col("B").top_k_by([dyn int: 1, col("x")]).over([col("A")])'
< /code>
It does work for k
Glaubst du, es ist ein Fehler?