Skip to content

BUG: Order of dict items in DataFrame.from_dict changes the result dataframe  #50461

Open
@Itayazolay

Description

@Itayazolay

Pandas version checks

  • I have checked that this issue has not already been reported.

  • I have confirmed this bug exists on the latest version of pandas.

  • I have confirmed this bug exists on the main branch of pandas.

Reproducible Example

df1 = pd.DataFrame.from_dict({'a': ['A1', 'A2'], 'b': 'B'}, orient='index')
df2 = pd.DataFrame.from_dict({'b': 'B', 'a': ['A1', 'A2']}, orient='index')

Issue Description

df1 has columns [0, 1] with the array exploded
df2 has only one column(0) with the array as value

Expected Behavior

Expected the order of the items of the dictionary to not impact on the result of the data frame.
Since it's possible to pass a combination of scalars and lists, I would expect it to work the same regardless the dict items order.

Installed Versions

INSTALLED VERSIONS

commit : 8dab54d
python : 3.11.0.final.0
python-bits : 64
OS : Linux
OS-release : 5.15.0-56-generic
Version : #62-Ubuntu SMP Tue Nov 22 19:54:14 UTC 2022
machine : x86_64
processor : x86_64
byteorder : little
LC_ALL : None
LANG : en_US.UTF-8
LOCALE : en_US.UTF-8

pandas : 1.5.2
numpy : 1.24.1
pytz : 2022.7
dateutil : 2.8.2
setuptools : 65.6.3
pip : 22.3.1
Cython : None
pytest : None
hypothesis : None
sphinx : None
blosc : None
feather : None
xlsxwriter : None
lxml.etree : None
html5lib : None
pymysql : None
psycopg2 : None
jinja2 : None
IPython : None
pandas_datareader: None
bs4 : None
bottleneck : None
brotli : None
fastparquet : None
fsspec : None
gcsfs : None
matplotlib : None
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
pyarrow : None
pyreadstat : None
pyxlsb : None
s3fs : None
scipy : None
snappy : None
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlwt : None
zstandard : None
tzdata : None

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugConstructorsSeries/DataFrame/Index/pd.array ConstructorsDataFrameDataFrame data structure

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions