Slide 11
Slide 11 text
@aseigneurin - @antoine_hars
Des méthodes utiles pour les TPs
df.agg(avg("hauteur_m"))
df.withColumn("genre_lati_lower",
functions.lower(df("genre_lati")))
def myCity(): String = "Paris"
df.withColumn("city",
functions.udf(myCity _).apply())
val df: DataFrame = ???
df.explode("categories", "category") {
categories: String => categories.split(",") }
● L’aggrégation via agg()
● L’ajout de colonnes via withColumn()
● L’utilisation d’UDF pour appliquer une
fonction à une Column
● L’explosion d’un record comme :
+----+----------+
|book|categories|
+----+----------+
| A1| a1,a2,a3|
| B1| b1,b2|
+----+----------+
+----+----------+--------+
|book|categories|category|
+----+----------+--------+
| A1| a1,a2,a3| a1|
| A1| a1,a2,a3| a2|
| A1| a1,a2,a3| a3|
| B1| b1,b2| b1|
| B1| b1,b2| b2|
+----+----------+--------+