Lưu ý
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử đăng nhập hoặc thay đổi thư mục.
Cần có ủy quyền mới truy nhập được vào trang này. Bạn có thể thử thay đổi thư mục.
Remove fields from a struct column.
Syntax
dropFields(*fieldNames)
Parameters
| Parameter | Type | Description |
|---|---|---|
fieldNames |
str | One or more field names to drop |
Returns
Column
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}}|
# +--------------+
Dropping multiple nested fields directly:
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}}|
# +--------------+