Skip to content

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

Closed
@soerenwolfers

Description

@soerenwolfers

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions