Skip to content

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

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
alexlenail opened this issue Oct 20, 2018 · 2 comments
Closed

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

alexlenail opened this issue Oct 20, 2018 · 2 comments

Comments

@alexlenail
Copy link
Contributor

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...

@mroeschke
Copy link
Member

This feature will be available in the next release (v0.24.0) or currently on master. xref #21223

In [9]: pd.__version__
Out[9]: '0.24.0.dev0+780.g145c2275e'

In [10]: s
Out[10]:
a    10
b     9
c    11
Name: w, dtype: int64

In [11]: df
Out[11]:
   x  y  z
p  3  6  b
q  4  7  a
r  5  8  c

In [12]: df.merge(s, how='left', left_on='z', right_index=True)
Out[12]:
   x  y  z   w
p  3  6  b   9
q  4  7  a  10
r  5  8  c  11

@alexlenail
Copy link
Contributor Author

@mroeschke incredible!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants