Oharra
Baimena behar duzu orria atzitzeko. Direktorioetan saioa has dezakezu edo haiek alda ditzakezu.
Baimena behar duzu orria atzitzeko. Direktorioak alda ditzakezu.
Calcula la suma de cada columna numérica para cada grupo.
Sintaxis
sum(*cols)
Parámetros
| Parámetro | Tipo | Descripción |
|---|---|---|
cols |
str | Nombres de columna. Se omiten las columnas no numéricas. |
Devoluciones
DataFrame
Ejemplos
df = spark.createDataFrame([
(2, "Alice", 80), (3, "Alice", 100),
(5, "Bob", 120), (10, "Bob", 140)], ["age", "name", "height"])
# Group-by name, and calculate the sum of the age in each group.
df.groupBy("name").sum("age").sort("name").show()
# +-----+--------+
# | name|sum(age)|
# +-----+--------+
# |Alice| 5|
# | Bob| 15|
# +-----+--------+
# Calculate the sum of the age and height in all data.
df.groupBy().sum("age", "height").show()
# +--------+-----------+
# |sum(age)|sum(height)|
# +--------+-----------+
# | 20| 440|
# +--------+-----------+