API: round() method to ignore non-numerical columns? · Issue #11885 · pandas-dev/pandas (original) (raw)

@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).