janitor.round_to_fraction(df: pandas.core.frame.DataFrame, column_name: Hashable = None, denominator: float = None, digits: float = inf) → pandas.core.frame.DataFrame[source]

Round all values in a column to a fraction.

This method mutates the original DataFrame.

Taken from https://github.com/sfirke/janitor/issues/235.

Also, optionally round to a specified number of digits.

Method-chaining usage:

# Round to two decimal places
df = pd.DataFrame(...).round_to_fraction('a', 2)
  • df – A pandas dataframe.

  • column_name – Name of column to round to fraction.

  • denominator – The denominator of the fraction for rounding

  • digits – The number of digits for rounding after rounding to the fraction. Default is np.inf (i.e. no subsequent rounding)


A pandas DataFrame with a column’s values rounded.