polars.DataFrame.sum#

DataFrame.sum(*, axis: Literal[0] = 0, null_strategy: NullStrategy = 'ignore') Self[source]#
DataFrame.sum(*, axis: Literal[1], null_strategy: NullStrategy = 'ignore') Series
DataFrame.sum(*, axis: int = 0, null_strategy: NullStrategy = 'ignore') Self | Series

Aggregate the columns of this DataFrame to their sum value.

Parameters:
axis

Either 0 or 1.

null_strategy{‘ignore’, ‘propagate’}

This argument is only used if axis == 1.

Examples

>>> df = pl.DataFrame(
...     {
...         "foo": [1, 2, 3],
...         "bar": [6, 7, 8],
...         "ham": ["a", "b", "c"],
...     }
... )
>>> df.sum()
shape: (1, 3)
┌─────┬─────┬──────┐
│ foo ┆ bar ┆ ham  │
│ --- ┆ --- ┆ ---  │
│ i64 ┆ i64 ┆ str  │
╞═════╪═════╪══════╡
│ 6   ┆ 21  ┆ null │
└─────┴─────┴──────┘
>>> df.sum(axis=1)
shape: (3,)
Series: 'foo' [str]
[
        "16a"
        "27b"
        "38c"
]