Search code examples
pythonpandasrounding

Round each number in a Python pandas data frame by 2 decimals


This works p_table.apply(pd.Series.round) however it has no decimal places

Documentation says

import pandas as pd

Series.round(decimals=0, out=None)

i tried this p_table.apply(pd.Series.round(2)) but get this error:

unbound method round() must be called with Series instance as first argument (got int instance instead)

How do I round all elements in the data frame to two decimal places?


Solution

  • import numpy as np
    np.round(p_table, decimals=2)