Round each number in a Python pandas data frame by 2 decimals
import numpy as np
np.round(p_table, decimals=2)
Since 0.17.0
version you can do .round(n)
df.round(2)
0 1 2 3
0 0.06 0.67 0.77 0.71
1 0.80 0.56 0.97 0.15
2 0.03 0.59 0.11 0.95
3 0.33 0.19 0.46 0.92
df
0 1 2 3
0 0.057116 0.669422 0.767117 0.708115
1 0.796867 0.557761 0.965837 0.147157
2 0.029647 0.593893 0.114066 0.950810
3 0.325707 0.193619 0.457812 0.920403
Below is a sample reproducible possible way of doing it using pandas round function.
# importing pandas as pd
import pandas as pd
# generate sample dataframe
df = pd.DataFrame(np.random.random([5, 4]), columns =["A", "B", "C"])
# use pandas dataframe.round()function to round off all the decimal values to 2 decimal
df.round(2)
# If you want to customize the round off by individual columns
df.round({"A":1, "B":2, "C":3})