Skip to content

ENH: Add suffixes for pd.concat when axis=1 #29615

Closed
@charlesdong1991

Description

@charlesdong1991

When I was trying to horizontally concatenate several DataFrames which contain some overlapping column names, and those overlapping columns would remain unchanged. However, it might be quite useful to have a suffixes argument as e.g DataFrame.merge has in practice, so that could easily add meaningful suffix to distinguish those overlapped columns. And this argument will be used only when axis=1.

While a walkaround for this is: pd.merge(df1, df2, left_index=True, right_index=True), but this cannot be applied in more dfs.

Just found out that this might be similar to #21791 and if this is the arg we want to add, I would be happy to work on this.

Minimum reproducible code:

>>> df1 = pd.DataFrame({"a": [1, 2, 3], "b": [2, 3, 4]})
>>> df2 = pd.DataFrame({"a": [4, 5, 6], "b": [7, 8, 9]})
>>> pd.concat([df1, df2], axis=1)

a | b | a | b
-- | -- | -- | --
1 | 2 | 4 | 7
2 | 3 | 5 | 8
3 | 4 | 6 | 9

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions