移除結構體欄位中的欄位。
語法
dropFields(*fieldNames)
參數
| 參數 | 類型 | 說明 |
|---|---|---|
fieldNames |
str | 一個或多個欄位名稱可刪除 |
退貨
資料行
Examples
from pyspark.sql import Row
from pyspark.sql.functions import col, lit
df = spark.createDataFrame([
Row(a=Row(b=1, c=2, d=3, e=Row(f=4, g=5, h=6)))])
df.withColumn('a', df['a'].dropFields('b')).show()
# +-----------------+
# | a|
# +-----------------+
# |{2, 3, {4, 5, 6}}|
# +-----------------+
df.withColumn('a', df['a'].dropFields('b', 'c')).show()
# +--------------+
# | a|
# +--------------+
# |{3, {4, 5, 6}}|
# +--------------+
直接丟棄多個巢狀欄位:
df.withColumn("a", col("a").dropFields("e.g", "e.h")).show()
# +--------------+
# | a|
# +--------------+
# |{1, 2, 3, {4}}|
# +--------------+
df.select(col("a").withField(
"e", col("a.e").dropFields("g", "h")).alias("a")
).show()
# +--------------+
# | a|
# +--------------+
# |{1, 2, 3, {4}}|
# +--------------+