distribuição cumulativa
Função de janela: retorna a distribuição cumulativa de valores dentro de uma partição da janela, ou seja, a fração de linhas que estão abaixo da linha atual.
Sintaxe
Python
from pyspark.sql import functions as sf
sf.cume_dist()
Parâmetros
Esta função não recebe nenhum parâmetro.
Devoluções
pyspark.sql.Column: a coluna para calcular a distribuição cumulativa.
Exemplos
Python
from pyspark.sql import functions as sf
from pyspark.sql import Window
df = spark.createDataFrame([1, 2, 3, 3, 4], "int")
w = Window.orderBy("value")
df.withColumn("cd", sf.cume_dist().over(w)).show()
Output
+-----+---+
|value| cd|
+-----+---+
| 1|0.2|
| 2|0.4|
| 3|0.8|
| 3|0.8|
| 4|1.0|
+-----+---+