Comments (3)
you're looking for list.len
, not len
len
just returns the length of the series. as that returns a single element, it broadcasts it to the length of the dataframe (see https://docs.pola.rs/user-guide/concepts/contexts/#selection)
In [17]: import polars as pl
...: df = pl.DataFrame([ pl.Series("col", [['A', 'U'], ['U', 'U']], dtype=pl.List(pl.Utf8)) ])
...: print(df.with_columns(pl.col('col').list.unique().list.len().alias('col uniq count')))
shape: (2, 2)
┌────────────┬────────────────┐
│ col ┆ col uniq count │
│ --- ┆ --- │
│ list[str] ┆ u32 │
╞════════════╪════════════════╡
│ ["A", "U"] ┆ 2 │
│ ["U", "U"] ┆ 1 │
└────────────┴────────────────┘
from polars.
closing then, but thanks for the issue! lmk if i've misunderstood and I can reopen
from polars.
@MarcoGorelli Thanks so much for identifying my issue and replying so quickly.
from polars.
Related Issues (20)
- predicate pushdown with `pl.Expr.cut`
- `.list.to_struct()` has non-deterministic behavior HOT 5
- Add `Expr.list.map_elements(func)` to perform a custom function on every element in a list HOT 2
- pl.from_pandas(..., nan_to_null=True) does not convert NaN to Null HOT 3
- Example of `.over()` 900x slower than group_by.agg.join (and over 50x slower than pandas) HOT 6
- Non-deterministic failure when materializing LazyFrame HOT 1
- LazyFrame - Unnested columns are missing in Lazy Frame HOT 8
- Add section about using `pipe` to the user guide HOT 1
- Regression: `list.sum()` inside WhenThen now returns a list HOT 1
- In pl.Series, nan_to_null parameter not respected with floats HOT 1
- When reading excel table data, you are advised to freely select the column name or column number to read data HOT 2
- When reading excel table data, allow selection of the column names/indices to read HOT 2
- Incorrect `ColumnNotFound` panic, which occurs only for LazyFrames HOT 2
- search_sorted does not work on boolean columns
- PanicException creating DataFrame with numpy array inside dict HOT 1
- `struct.rename_fields` does not work on structs with categorical columns after scanning a parquet file with more than one row group. HOT 4
- `SchemaFieldNotFound` on LazyFrame when using `select` after `struct.field(...)` HOT 1
- Handle `pd.NaT` values in lists passed to DataFrame constructor HOT 5
- `.struct.field("*")` PanicException: no `columns` expected at this point
- unique + cross-join PanicException on streaming engine
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from polars.