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

concat sorts columns without preserving order #9001

Closed
EVaisman opened this issue Dec 4, 2014 · 1 comment
Closed

concat sorts columns without preserving order #9001

EVaisman opened this issue Dec 4, 2014 · 1 comment
Labels
API Design Bug Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@EVaisman
Copy link

EVaisman commented Dec 4, 2014

Although it's my desired behavior, I realize perhaps this is not the desired behavior, but I think it's reasonable to bring up.

If I want to concat two data frames and their column names are the same, the order is preserved:

>>> df1 = pd.DataFrame(columns=["A","1"])
>>> pd.concat([df1,df1])
Empty DataFrame
Columns: [A, 1]
Index: []

However, if they are not, it seems they are sorted:

>>> df2 = pd.DataFrame(columns=["A","2"])
>>> pd.concat([df1,df2])
Empty DataFrame
Columns: [1, 2, A]
Index: []

Would it be reasonable to try to preserve the order? So the output would be:

>>> pd.concat([df1,df2])
Empty DataFrame
Columns: [A, 1, 2]
Index: []

I realize that, in an ordered list, "A" doesn't come before "1" or "2", but in both df1 and df2, "A" does come before "1" and "2".

@jreback
Copy link
Contributor

jreback commented Dec 4, 2014

this is a dupe of #4588

thanks for the report

@jreback jreback closed this as completed Dec 4, 2014
@jreback jreback added Bug Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode API Design labels Dec 4, 2014
@jreback jreback added this to the 0.16.0 milestone Dec 4, 2014
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
API Design Bug Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

2 participants