Skip to content

pd.read_json May Not Maintain Numeric String Index #28556

Closed
@WillAyd

Description

@WillAyd
>>> df = pd.DataFrame(range(3), index=list("123"))
>>> df.to_json(orient="split")
'{"columns":[0],"index":["1","2","3"],"data":[[0],[1],[2]]}'
>>> pd.read_json(df.to_json(orient="split"), orient="split").index
Int64Index([1, 2, 3], dtype='int64')

Note that the string nature of the values should be preserved via roundtrip here, but ends up being lossy anyway. Noted during refactor of #28510

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugDtype ConversionsUnexpected or buggy dtype conversionsIO JSONread_json, to_json, json_normalize

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions