I have a (large ~ 1million) Scala Spark DataFrame with the following data:
id,score
1,0.956
2,0.977
3,0.855
4,0.866
...
How do I discretise/round the scores to the nearest 0.05 decimal place?
Expected result:
id,score
1,0.95
2,1.00
3,0.85
4,0.85
...
Would like to avoid using UDF to maximise performance.
The answer can be simplifier:
dataframe.withColumn("rounded_score", round(col("score"), 2))
there is a method
def round(e: Column, scale: Int)
Round the value of
e
toscale
decimal places with HALF_UP round mode
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With