-
-
Notifications
You must be signed in to change notification settings - Fork 19.6k
Closed
Labels
API DesignEnhancementNumeric OperationsArithmetic, Comparison, and Logical operationsArithmetic, Comparison, and Logical operations
Milestone
Description
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
Labels
API DesignEnhancementNumeric OperationsArithmetic, Comparison, and Logical operationsArithmetic, Comparison, and Logical operations