GithubHelp home page GithubHelp logo

Comments (5)

stinodego avatar stinodego commented on July 29, 2024 1

Oh yeah I think you're right..

from polars.

DeflateAwning avatar DeflateAwning commented on July 29, 2024 1

Awesome, thanks! Good lesson about aliasing a Series's name though; didn't know I could do that :)

from polars.

cmdlineluser avatar cmdlineluser commented on July 29, 2024

Yeah, it seems currently there is a hardcoded check for this potential situation:

df = pl.DataFrame({"count": ["a", "a", "b"]})

df["count"].value_counts()
# DuplicateError: using `value_counts` on a column named 'count' would lead to duplicate column names

It was recently added for GroupBy.len due to similar issues #15222

df["count"].to_frame().group_by("*").len("occurences")
# shape: (2, 2)
# ┌───────┬────────────┐
# │ count ┆ occurences │
# │ ---   ┆ ---        │
# │ str   ┆ u32        │
# ╞═══════╪════════════╡
# │ a     ┆ 2          │
# │ b     ┆ 1          │
# └───────┴────────────┘

from polars.

stinodego avatar stinodego commented on July 29, 2024

We do not add name parameters to operations on a single column.

DataFrame.with_row_index needs a name parameter because the name may clash with an existing column in the dataframe.

Series/Expr.value_counts don't need a name parameter because you can just use alias before:

df["count"].alias("my_custom_name").value_counts()

I'll add a hint to the error message.

from polars.

alexander-beedie avatar alexander-beedie commented on July 29, 2024

Series/Expr.value_counts don't need a name parameter because you can just use alias before:

Actually, I think we probably should add a name param here, as we force the result name to "count". The user shouldn't have to change their column names to account for us forcing one on them 🤔 I'll make a PR with an example and you can see what you think.

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.