Jac*_*ack 0 python apache-spark-sql
from pyspark.sql.functions import *
ghj=finalDF.withColumn("temp", explode(split(regexp_replace(to_json(struct(col("sum(P0)"), col("sum(P1)"), col("sum(P2)"), col("sum(P3)"), col("sum(P4)"), col("sum(P5)"))),"""[\{"\}]""",""), ",")))
.withColumn("Priority", split(col("temp"),":")[0])
.withColumn("Count", split(col("temp"),":")[1]).select(col("NAME"), col("SHORT_DESCRIPTION"), col("Priority"), col("Count")).show()
Run Code Online (Sandbox Code Playgroud)
您不能简单地将 Python 语句延续到下一行。\每行末尾都需要有一个延续:
ghj=finalDF.withColumn(.....)\
.withColumn(.....)\
.withColumn(.....).show()
Run Code Online (Sandbox Code Playgroud)
确保 后没有其他符号(甚至空格)\。
作为建议的替代方案\,您还可以使用括号(注意,没有逗号):
ghj = (
finalDF.withColumn(.....)
.withColumn(.....)
.withColumn(.....)
.show()
)
Run Code Online (Sandbox Code Playgroud)