Reputation: 525
For a pyspark data frame, Do you know how to convert numbers with decimals into percentage format? I can even determine the number of decimal points I want to keep.
Upvotes: 3
Views: 7386
Reputation: 31490
You can multiply with 100
df.withColumn("rate",(col("rate") * 100).cast("int")).show()
+---+---+----+
| id|row|rate|
+---+---+----+
| A| 1| 1|
+---+---+----+
df.withColumn("rate",concat((col("rate") * 100).cast("int"),lit('%'))).show()
+---+---+----+
| id|row|rate|
+---+---+----+
| A| 1| 1%|
+---+---+----+
Upvotes: 5