Skip to content

pd.DataFrame.to_dict('records') increase precision unexpectedly #12

@tashrifbillah

Description

@tashrifbillah

When a Pandas DataFrame is converted into a Python dictionary:

data_blob.extend(chunk.to_dict('records'))

precision of some numbers increase unexpectedly (0.999-->0.999000000001):

image(1)

There is also a post on stackoverflow about it.


Tashrif's solution:

chunk.round(5).to_dict('records')

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions