Skip to content

Creating DataFrame from dict with columns orientation does not preserve order of index #26072

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
bchu opened this issue Apr 13, 2019 · 3 comments
Labels
Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode

Comments

@bchu
Copy link

bchu commented Apr 13, 2019

import pandas as pd
d = {'column': {'one': 1, 'two': 2, 'three': 3}}
pd.DataFrame(d) # Or pd.DataFrame.from_dict(d, orient='columns')

results in:

       column
one         1
three       3
two         2

instead of what we expect:

       column
one         1
two         2
three       3

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.5.final.0
python-bits: 64
OS: Darwin
OS-release: 18.2.0
machine: x86_64
processor: i386
byteorder: little
LC_ALL: None
LANG: en_US.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.24.2
pytest: 4.4.0
pip: 19.0.3
setuptools: 39.0.1
Cython: 0.28.3
numpy: 1.15.4
scipy: 1.2.1
pyarrow: 0.13.0
xarray: 0.10.0
IPython: 7.4.0
sphinx: None
patsy: 0.4.1
dateutil: 2.7.2
pytz: 2018.5
blosc: None
bottleneck: 1.2.1
tables: 3.4.2
numexpr: 2.6.9
feather: None
matplotlib: 2.1.0
openpyxl: None
xlrd: None
xlwt: None
xlsxwriter: None
lxml.etree: 4.2.0
bs4: None
html5lib: 0.9999999
sqlalchemy: 1.1.10
pymysql: None
psycopg2: 2.7.1 (dt dec pq3 ext lo64)
jinja2: 2.10
s3fs: None
fastparquet: 0.3.0
pandas_gbq: None
pandas_datareader: None
gcsfs: 0.2.1

@jreback
Copy link
Contributor

jreback commented Apr 13, 2019

dict ordering is not guaranteed before 3.6; so this is as expected; you didn’t show which version you are using

@bchu
Copy link
Author

bchu commented Apr 13, 2019

Sorry, just added. This is on Python 3.6

@jreback
Copy link
Contributor

jreback commented Apr 13, 2019

this a duplicate of #24859 with a slight variation. you are welcome to have a look.

@jreback jreback closed this as completed Apr 13, 2019
@jreback jreback added Duplicate Report Duplicate issue or pull request Reshaping Concat, Merge/Join, Stack/Unstack, Explode labels Apr 13, 2019
@jreback jreback added this to the No action milestone Apr 13, 2019
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 Reshaping Concat, Merge/Join, Stack/Unstack, Explode
Projects
None yet
Development

No branches or pull requests

2 participants