Comments (3)
Agreed on the rename.
I don't think the index should be part of the RLE method by default. It is not an essential part of the RLE definition. Though possibly an include_index
parameter would make sense - but please open a separate issue for that.
from polars.
@cmdlineluser I am tempted to also change the field order of the struct to value
/len
. That way it matches value_counts
. What do you think?
EDIT: Nevermind, it's probably not a good idea as the standard RLE places len
before value
, e.g. 12W1B12W3B24W1B14W
.
from polars.
Side note: Would it make sense for rle()
to also return the row index? {index, value, len}
The particular use-case being wanting the original row index after performing a .filter()
df = pl.DataFrame({"foo": ["a", "a", "a", "b", "c", "c"]})
df.select(pl.col("foo").rle())
# shape: (3, 1)
# ┌───────────┐
# │ foo │
# │ --- │
# │ struct[2] │
# ╞═══════════╡
# │ {3,"a"} │
# │ {1,"b"} │
# │ {2,"c"} │
# └───────────┘
We can calculate it from the length, but it's a little awkward:
(df.select(pl.col("foo").rle())
.with_columns(
index = pl.col("foo").struct["lengths"].cum_sum().shift().fill_null(0)
)
#.filter(...)
)
# shape: (3, 2)
# ┌───────────┬───────┐
# │ foo ┆ index │
# │ --- ┆ --- │
# │ struct[2] ┆ i32 │
# ╞═══════════╪═══════╡
# │ {3,"a"} ┆ 0 │
# │ {1,"b"} ┆ 3 │
# │ {2,"c"} ┆ 4 │
# └───────────┴───────┘
from polars.
Related Issues (20)
- Join on struct fails with "not implemented", but on struct + other column fails silently HOT 1
- Add `mode` argument in `pl.DataFrame.write_csv` HOT 1
- Wrong document in arguments `group_by` of `DataFrame.upsample` HOT 5
- Incorrect result from projection_pushdown HOT 6
- np.NaT should get converted to null when converting from NumPy HOT 2
- Panic when building a Series of lists without an inner dtype
- Why two struct series with different type are equal?
- Upsample fills time_column but not groups HOT 5
- Setup CodSpeed for PR benchmarks HOT 1
- polars' maximum length reached. Consider installing 'polars-u64-idx' with a dataframe of 12K rows HOT 3
- join_asof should allow for strict inequalities on the "on" column
- Inconsistent result from comm_subplan_elim HOT 2
- Polars write_database Connection Issue with Redshift: Unrecognized Configuration Parameter HOT 5
- Support `group_by` on columns of type `List(String)` HOT 3
- Ability to disable jemalloc HOT 3
- `.reshape((-1, -1))` causes PanicException HOT 3
- Schema contradiction with polars.LazyFrame.fill_null(matches_supertype=True)
- Regression in common subplan elimination when cached node is used HOT 2
- Python Polars Import Fail on Aarch64 Linux HOT 6
- [DRAFT] Predicate pushdown broken by lazy `pl.concat` HOT 12
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.