Skip to content

Ability to merge even if no common columns #7203

Closed
@RacingTadpole

Description

@RacingTadpole

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Duplicate ReportDuplicate issue or pull requestReshapingConcat, Merge/Join, Stack/Unstack, Explode

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions