以保留小数点后两位小数为例:
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.random([5, 5]), columns=[‘A1’, ‘A2’, ‘A3’,‘A4’,‘A5’])
print(df)
print(“==================================”)
print(df.round(2))
1.2 数据框分别设置不同小数位数
以A1列保留小数点后一位、A2列保留小数点后两位为例
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.random([5, 5]), columns=[‘A1’, ‘A2’, ‘A3’,‘A4’,‘A5’])
print(df)
print(“===========================