구조체 열에서 필드를 제거합니다.
문법
dropFields(*fieldNames)
매개 변수
| 매개 변수 | 유형 | 설명 |
|---|---|---|
fieldNames |
str | 삭제할 하나 이상의 필드 이름 |
Returns
칼럼
예제
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}}|
# +--------------+