Giter VIP home page Giter VIP logo

Comments (3)

stinodego avatar stinodego commented on June 20, 2024 1

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.

stinodego avatar stinodego commented on June 20, 2024 1

@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.

cmdlineluser avatar cmdlineluser commented on June 20, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.