您应该使用该
round函数,然后将其强制转换为整数类型。但是,请勿对
round函数使用第二个参数。通过使用2,它将四舍五入到小数点后两位,
cast然后整数将
舍 入到最接近的数字。
而是使用:
df2 = df.withColumn("col4", func.round(df["col3"]).cast('integer'))
您应该使用该
round函数,然后将其强制转换为整数类型。但是,请勿对
round函数使用第二个参数。通过使用2,它将四舍五入到小数点后两位,
cast然后整数将
而是使用:
df2 = df.withColumn("col4", func.round(df["col3"]).cast('integer'))