Skip to content

pd.read_json and orient="index" sorts results #28557

Closed
@WillAyd

Description

@WillAyd

Note that the order of input is not maintained with orient="index"

>>> df = pd.DataFrame(range(3), index=range(3, 0, -1))
>>> df
   0
3  0
2  1
1  2
>>> df.to_json(orient="index")
'{"3":{"0":0},"2":{"0":1},"1":{"0":2}}'
>>> pd.read_json(df.to_json(orient="index"), orient="index")
   0
1  2
2  1
3  0

This is not necessarily a problem as by definition JSON objects are unordered, but preserving the order here would be a logical follow up to #27309

Metadata

Metadata

Assignees

No one assigned

    Labels

    IO JSONread_json, to_json, json_normalize

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions