Skip to content
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ENH: allow pd.merge() variables right_on and left_on to accept pd.Index() array_likes #58279

Open
1 of 3 tasks
loewenm opened this issue Apr 16, 2024 · 0 comments
Open
1 of 3 tasks
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member

Comments

@loewenm
Copy link

loewenm commented Apr 16, 2024

Feature Type

  • Adding new functionality to pandas

  • Changing existing functionality in pandas

  • Removing existing functionality in pandas

Problem Description

When passing a Pandas Index as a variable in either right_on or left_on in a pd.merge(), the result is a KeyError

KeyError: array(['label 1', 'label 2', 'label 3'], dtype=object)

The documentation says that you can pass "label or list, or array-like". While pd.Index() might not be exactly an array-like, it does seem counterproductive to exclude the very thing that should be referenced when merging...

Feature Description

Simple request: Please expand allowable datastructures for right_on and left_on to be "label, list, array-like, or index".

Alternative Solutions

Temporary solution is to covert pd.Index to_lists():

merged_df = pd.merge(
left=df_A,
right=df_B,
right_on=df_A.columns.to_list(),
left_on=df_B.columns.to_list(),
how="left",
)

Additional Context

I believe this probably just a simple "oh-yeah" moment...

@loewenm loewenm added Enhancement Needs Triage Issue that has not been reviewed by a pandas team member labels Apr 16, 2024
@loewenm loewenm changed the title ENH: allow pd.merge() variable right_on and left_on to accept pd.Index() array_likes ENH: allow pd.merge() variables right_on and left_on to accept pd.Index() array_likes Apr 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Enhancement Needs Triage Issue that has not been reviewed by a pandas team member
Projects
None yet
Development

No branches or pull requests

1 participant