Skip to content

Why does df.merge(x) not work when x is a pd.Series?  #23250

Closed
@alexlenail

Description

@alexlenail

Code Sample, a copy-pastable example if possible

s = pd.Series([10, 9, 11], index=['a', 'b', 'c'], name='w')

df = pd.DataFrame([[3, 4, 5], [6, 7, 8], ['b', 'a', 'c']], index=['x', 'y', 'z'], columns=['p', 'q', 'r']).transpose()

df.merge(s, how='left', left_on='z', right_index=True)  # fails

df.merge(s.to_frame(), how='left', left_on='z', right_index=True)  # succeeds

We can all keep using .to_frame(), but I feel like the desired behavior of merging a dataframe with a series is well defined.

Food for thought...

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