Skip to content

Add parameter always_suffix to DataFrame.merge #18260

Closed
@lverweijen

Description

@lverweijen

Code Sample

A = pd.DataFrame({'a': [1, 2, 3], 'b': [4, 5, 6]})
B = pd.DataFrame({'a': [1, 2, 3], 'c': [7, 8, 9]})

def foo(A, B):
    C = A.merge(B, on=['a'])
    C['c']  # Where does c originate from?

Problem description

There is no way to explicitely specificy whether 'c' originates from A or B. This makes code harder to maintain. Better would be if I could write something like:

C = A.merge(B, on=['a'], always_suffix=True)
C['c_y]  # Obvious that C comes from B, because suffixes are always created

Metadata

Metadata

Assignees

No one assigned

    Labels

    API DesignDuplicate 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