Skip to content

Constructor reorders columns and rows for (lists or dicts) of dicts #26587

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
soerenwolfers opened this issue May 31, 2019 · 3 comments
Closed
Labels
Duplicate Report Duplicate issue or pull request

Comments

@soerenwolfers
Copy link

Code Sample

import pandas as pd
print(pd.DataFrame({0:{'B':'First row','A':'Second row'}}))
print(pd.DataFrame([{'B':'First column','A':'Second column'}]))

Results in

            0
A  Second row
B   First row
               A             B
0  Second column  First column

Problem description

The two constructor calls above reorder the rows or columns, respectively, alphabetically, so the row or column, respectively, indexed by 'A' always comes first.

Expected Output

The order of the dict should be preserved now that Python dictionaries are officially ordered.
Hence, the row or column, respectively, indexed by 'A' should come second.

I don't need to make an argument for this, because pandas itself has already decided so:
https://pandas.pydata.org/pandas-docs/version/0.23.0/whatsnew.html#whatsnew-0230-api-breaking-dict-insertion-order

Versions

Tested with pandas 0.24.2 and Python 3.7

@WillAyd
Copy link
Member

WillAyd commented May 31, 2019

This is a duplicate of quite a few issues. The problem with this is that there is no such thing as guaranteed ordering in two dimensions.

@WillAyd
Copy link
Member

WillAyd commented Jun 2, 2019

Closing as a duplicate of #24859

@WillAyd WillAyd closed this as completed Jun 2, 2019
@WillAyd WillAyd added the Duplicate Report Duplicate issue or pull request label Jun 2, 2019
@soerenwolfers
Copy link
Author

soerenwolfers commented Jun 2, 2019

@WillAyd I don't understand

There is no such thing as guaranteed ordering in two dimensions.

Do you mean

There may not be a unique ordering if multiple dicts are passed in.

If so, what prevents pandas from using the unique order if it exists?

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
Projects
None yet
Development

No branches or pull requests

2 participants