'How to use fold in polars?

in the API document.

df = pl.DataFrame(
    {
        "a": [2, 1, 3],
        "b": [1, 2, 3],
        "c": [1.0, 2.0, 3.0],
    }
)
df.fold(lambda s1, s2: s1 + s2)

what is s1 and s2 refer to?

In user guide:

out = df.select(
    pl.fold(acc=pl.lit(0), f=lambda acc, x: acc + x, exprs=pl.col("*")).alias("sum"),
)
print(out)

what is acc?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source