Skip to content

Ability to merge even if no common columns #7203

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

Closed
RacingTadpole opened this issue May 22, 2014 · 3 comments
Closed

Ability to merge even if no common columns #7203

RacingTadpole opened this issue May 22, 2014 · 3 comments
Labels
Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@RacingTadpole
Copy link

Hi,
I would find it very helpful to be able to merge dataframes without common columns, (which is allowed in R), e.g.

x = DataFrame({'farm' : ['A','B','C']})
y = DataFrame({'crop':['wheat','millet']})

so that x.merge(y, how='outer') returns:

  farm    crop
0    A   wheat
1    A  millet
2    B   wheat
3    B  millet
4    C   wheat
5    C  millet

Currently pandas returns: MergeError: No common columns to perform merge on.

One work-around is to set the indices of x and y to zero, perform a join and the reset the index, as per this StackOverflow post. Another use case is here.

Alternatively, if there is a better solution, please let me know. Thanks!

@jreback
Copy link
Contributor

jreback commented May 22, 2014

looks like a dupe of: #5401 ?

@RacingTadpole
Copy link
Author

Thanks, I didn't see that one. Yes, although my suggested solution is a little different, ie. generalizing how merge works with how='outer', rather than adding a new how='cross'.

@jreback
Copy link
Contributor

jreback commented May 22, 2014

going to close this as a dupe (but its linked); I think its better add a different how='cross' to avoid accidental merges when their are no overlapping columns (and it wasn't explicitly specified). but that's in the future when this is implemented.

of course if you are interested in doing a PR, would be great!

this isn't that difficult as I think the proposed soln is actually fine;

@jreback jreback closed this as completed May 22, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

2 participants