Skip to content

API: round() method to ignore non-numerical columns? #11885

Closed
@jorisvandenbossche

Description

@jorisvandenbossche

If you call the new round method on a mixed dataframe (not only numerical columns), you get an error:

In [1]: df = pd.DataFrame({'floats':[0.123, 0.156, 5.687], 'strings': ['a', 'b', 'c']})

In [2]: df.round(2)
TypeError: can't multiply sequence by non-int of type 'float'

In [3]: df.round()
AttributeError: 'str' object has no attribute 'rint'

Would it be better to ignore these non-numerical columns instead of raising an error?
Another option would be to drop these columns (like numerical aggregations like df.mean() do).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions