请您参考如下方法:
从 Spark 2.4.0 开始,这可以使用 array_except 轻松解决。 举个例子
from pyspark.sql import functions as F
#example df
df=sqlContext.createDataFrame(pd.DataFrame(data=[[["hello", "world"],
["world"]],[["sample", "overflow", "text"], ["sample", "text"]]], columns=["A", "B"]))
df=df.withColumn('difference', F.array_except('A', 'B'))
更多类似的数组操作,我推荐这篇博文 https://www.waitingforcode.com/apache-spark-sql/apache-spark-2.4.0-features-array-higher-order-functions/read
