Skip to content
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

BUG: merge fails to rename when name already exists #4975

Closed
jseabold opened this issue Sep 25, 2013 · 3 comments · Fixed by #4989
Closed

BUG: merge fails to rename when name already exists #4975

jseabold opened this issue Sep 25, 2013 · 3 comments · Fixed by #4989
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@jseabold
Copy link
Contributor

Trying to merge a bunch of files in a loop. I realize there's a better way to do this and a workaround, but it took me a second to realize what was going on here.

w = pd.DataFrame(np.random.random((4,2)), columns=["x", "y"]) 
x = pd.DataFrame(np.random.random((4,2)), columns=["x", "y"])
y = pd.DataFrame(np.random.random((4,2)), columns=["x", "y"])
z = pd.DataFrame(np.random.random((4,2)), columns=["x", "y"])

dta = x.merge(y, left_index=True, right_index=True).merge(z, left_index=True, right_index=True, how="outer")

dta.merge(w, left_index=True, right_index=True)
@jreback
Copy link
Contributor

jreback commented Sep 25, 2013

would this work for you?

dups, which make certain operations a bit odd

In [22]: concat([w,x,y,z],axis=1)
Out[22]: 
          x         y         x         y         x         y         x         y
0 -0.563069 -0.961155  0.431668  0.878735 -0.388918  0.922276 -0.519004  0.801015
1 -1.562759 -0.273918 -1.019135 -1.245221 -0.428684 -1.153576  0.573085  1.766883
2  0.538920 -0.196340  0.947958 -1.089876  0.681975 -0.176980  0.572076  0.932001
3 -0.583187  0.041399  0.420735 -1.839026 -0.827691 -0.996057 -1.050309 -0.832534

or

In [23]: concat([w,x,y,z],keys=['w','x','y','z'],axis=1)
Out[23]: 
          w                   x                   y                   z          
          x         y         x         y         x         y         x         y
0 -0.563069 -0.961155  0.431668  0.878735 -0.388918  0.922276 -0.519004  0.801015
1 -1.562759 -0.273918 -1.019135 -1.245221 -0.428684 -1.153576  0.573085  1.766883
2  0.538920 -0.196340  0.947958 -1.089876  0.681975 -0.176980  0.572076  0.932001
3 -0.583187  0.041399  0.420735 -1.839026 -0.827691 -0.996057 -1.050309 -0.832534

@jseabold
Copy link
Contributor Author

Yeah, that's nice. It won't work for me (I have a terrible situation) and ended up going a completely different route. Just found the error message to be pretty cryptic until I thought about it.

@jreback
Copy link
Contributor

jreback commented Sep 25, 2013

ok....that's an easy fix then

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants