Я пытаюсь вычислить среднее значение для получения прибыли.
Spark 2.4.4
DataFrame выглядит так: -
+----------------+----------------+-------------------+
| Customer |CustomerCount |profit|
+----------------+----------------+-------------------+
|Customer_162 | 8| 0.28|
|Customer_2634 | 1|0.31|
|Customer_1482 | 8|0.28 |
+----------------+----------------+-------------------+
Code:
newdf.select("Customer","CustomerCount","profit")
.agg(sum("profit")
.alias("sum"),
count("CustomerCount").alias("count"))
.withColumn("Mean", round(col("sum") / sum("count").over(),2))
.show()
Current Output shows like
+----------------+-----+----+
| sum|count|Mean|
+----------------+-----+----+
, но я пытаюсь получить результат как
+----------------+----------------+--------------+
| Customer |CustomerCount |profit| Mean
+----------------+----------------+---------------+
|Customer_162 | 8| 0.28 |0.29
|Customer_2634 | 1|0.31 |0.29
|Customer_1482 | 8|0.28 |0.29
+----------------+----------------+--------+
С уважением