Skip to content

Commit

Permalink
Adding docs for len()
Browse files Browse the repository at this point in the history
  • Loading branch information
Bidek56 committed Aug 31, 2024
1 parent 3185a82 commit fba7eb0
Showing 1 changed file with 42 additions and 1 deletion.
43 changes: 42 additions & 1 deletion polars/lazy/functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,48 @@ export function head(column: Series | ExprOrString, n?): Series | Expr {
}
return exprToLitOrExpr(column, false).head(n);
}
/** Return the number of elements in the column. */
/** Return the number of elements in the column.
This is similar to `COUNT(*)` in SQL.
@return Expr - Expression of data type :class:`UInt32`.
@example
```
>>> const df = pl.DataFrame(
... {
... "a": [1, 2, None],
... "b": [3, None, None],
... "c": ["foo", "bar", "foo"],
... }
... )
>>> df.select(pl.len())
shape: (1, 1)
┌─────┐
│ len │
│ --- │
│ u32 │
╞═════╡
│ 3 │
└─────┘
```
Generate an index column by using `len` in conjunction with :func:`intRange`.
```
>>> df.select(
... pl.intRange(pl.len(), dtype=pl.UInt32).alias("index"),
... pl.all(),
... )
shape: (3, 4)
┌───────┬──────┬──────┬─────┐
│ index ┆ a ┆ b ┆ c │
│ --- ┆ --- ┆ --- ┆ --- │
│ u32 ┆ i64 ┆ i64 ┆ str │
╞═══════╪══════╪══════╪═════╡
│ 0 ┆ 1 ┆ 3 ┆ foo │
│ 1 ┆ 2 ┆ null ┆ bar │
│ 2 ┆ null ┆ null ┆ foo │
└───────┴──────┴──────┴─────┘
```
*/
export function len(): any {
return _Expr(pli.len());
}
Expand Down

0 comments on commit fba7eb0

Please sign in to comment.