当值为 3.0 时,使用以下构造删除小数精度 (. & 0),当值为 3.12345 时,四舍五入到小数点后 4 位
import pandas as pd
df1 = pd.DataFrame({'Price':[1.0,2.12345,3.0,4.67892]})
df1["Price"] = df1["Price"].apply(lambda x: round(x,4) if x%1 else int(x))
print(df1)
舍入有效,但不能转换为 int。
慕的地8271018
相关分类