Skip to content

Column information lost in to_json() if data frame is empty #7445

Closed
@aizvorski

Description

@aizvorski

Create empty dataframe with a column and write it out with to_json(), then read it back in:

In [55]: s = pandas.DataFrame({'test': [] }, index=[] ).to_json(orient='columns')
In [56]: s
Out[56]: '{}'
In [57]: str( pandas.read_json(s, orient='columns') )
Out[57]: 'Empty DataFrame\nColumns: []\nIndex: []'

I think the expected string is '{"test":{}}'

This situation arises when code filters data frames and writes them out, while not being very careful to make sure the filtered frames contain at least one row.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugIO JSONread_json, to_json, json_normalize

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions