Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Fix stubname equal suffix in wide to long function#57868

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
tqa236 wants to merge2 commits intopandas-dev:main
base:main
Choose a base branch
Loading
fromtqa236:fix-wide-to-long

Conversation

tqa236
Copy link
Contributor

Aspandas allows an index in a multiindex and a column to have the same name, I think it's reasonable to allow stubname equal suffix.

However, I think the root cause is in themelt function. It's stated in the docstring that

    value_name : scalar, default 'value'        Name to use for the 'value' column, can't be an existing column label.

But ifvalue_name == var_name, illogical result is returned. Example:

df = pd.DataFrame(    {        "A": {0: "a", 1: "b", 2: "c"},        "B": {0: 1, 1: 3, 2: 5},        "C": {0: 2, 1: 4, 2: 6},    })pd.melt(    df,    id_vars=["A"],    value_vars=["B"],    var_name="myVarname",    value_name="myVarname",)

Result:

image

I think it's more reasonable to also raise an error ifvalue_name == var_name inmelt

@tqa236
Copy link
ContributorAuthor

Hi@mroeschke, can you take a look at this PR, please? It should be ready for review.

@mroeschkemroeschke added the ReshapingConcat, Merge/Join, Stack/Unstack, Explode labelApr 23, 2024
Copy link
Member

@datapythonistadatapythonista left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks@tqa236, and sorry for the delay. Not sure if two branches got mixed, seems like half of the changes here are unrelated to the topic of this PR.

@tqa236
Copy link
ContributorAuthor

hi@datapythonista, thank you for the review. I also force pushed to the branch because I noticed that you also didn't make any comment on the actual content of the PR. Now this PR should be ready for review.

@datapythonista
Copy link
Member

Thanks for the update here@tqa236. The fix you implemented seems a hack, not the proper fix. You should identify what's causing the exception, which seem kind of unrelated, and fix that. Please let me know if you want to have a look more in detail to the actual problem, otherwise we can close this PR.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@datapythonistadatapythonistadatapythonista left review comments

Assignees
No one assigned
Labels
ReshapingConcat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

BUG: pd.wide_to_long can't handle stubname equal to suffix
3 participants
@tqa236@datapythonista@mroeschke

[8]ページ先頭

©2009-2025 Movatter.jp