Skip to content

DataFrame.to_dict not using python types #19381

Closed
@affanshahid

Description

@affanshahid

I have a dataframe that I need to convert to a dict and add it to another dict which is converted to json in the end. Unfortunately since .to_dict() does not use standard python types I get the following:

TypeError: Object of type 'int32' is not JSON serializable

My code is something like the following:

output = {
    'foo': 1,
    'bar': 2
}
...
df = ...
output['baz'] = df.to_dict()

send(json.dumps(output))

Using dumps results in the above error. This is related to #13258 where an 'easy way' was mentioned but I'm not sure what it is.

Would appreciate any help

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions