Skip to content

Initializing DataFrom from list of OrderedDicts does not preserve Column order #13808

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
cod3monk opened this issue Jul 26, 2016 · 2 comments
Closed
Labels
Duplicate Report Duplicate issue or pull request Enhancement Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Milestone

Comments

@cod3monk
Copy link

>>> import pandas as pd
>>> from collections import OrderedDict
>>> od = [OrderedDict([('z', 0), ('a', 1), ('*', 2)])]
>>> pd.DataFrame(od)
   *  a  z
0  2  1  0
>>> pd.DataFrame.from_dict(od)
   *  a  z
0  2  1  0

If OrderedDicts are used, I would expect the column order of the first OrderDict that is encountered to be preserved, as the following:

>>> pd.DataFrame(od, columns=od[0].keys())
   z  a  *
0  0  1  2
>>>

If different orders occur in the list, the earlier would overwrite the later. If new columns are introduced with subsequent list entries, I would expect all new columns to be appended to the original columns, with their relative order preserved.

@jreback
Copy link
Contributor

jreback commented Jul 26, 2016

this is a duplicate of ##13304

which is already in master and will be in 0.19.0, see here

@jreback jreback closed this as completed Jul 26, 2016
@jreback jreback added Enhancement Reshaping Concat, Merge/Join, Stack/Unstack, Explode Duplicate Report Duplicate issue or pull request labels Jul 26, 2016
@jreback jreback added this to the 0.19.0 milestone Jul 26, 2016
@cod3monk
Copy link
Author

cod3monk commented Jul 26, 2016 via email

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

No branches or pull requests

2 participants