Skip to content

ENH: Using built-in round on a series #11763

Closed
@Dr-Irv

Description

@Dr-Irv

Is there some philosophical reason that round(Series) and round(Dataframe) is not defined? See the example below. Being able to write round() as a function of a Dataframe or Series, as opposed to doing it afterwards would be nice. I'm willing to implement __round__() to make it work, but don't want to go down that path if there is some reason __round__() is not implemented.

Example:

    import pandas as pd
    import numpy as np
    df =  pd.DataFrame(np.random.randn(10, 3), columns=['A', 'B', 'C'])
    print (df.A.round())
    print (round(df))

Produces

0   -2
1    1
2   -1
3   -1
4    2
5    0
6    0
7    0
8   -2
9    0
Name: A, dtype: float64
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-8-9d2be9cbdc70> in <module>()
      3 df =  pd.DataFrame(np.random.randn(10, 3), columns=['A', 'B', 'C'])
      4 print (df.A.round())
----> 5 print (round(df))

TypeError: type DataFrame doesn't define __round__ method

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions