我正在尝试编写如下语句: profileId =“某些值” df.withColumn(“ ProfileId”,col(profileId))并在DataBricks上获得AnalysisException。据我所知,这应该工作,所以我想知道问题出在哪里。任何帮助将不胜感激。
答案 0 :(得分:1)
尝试将lit
与变量一起使用,例如
%py
from pyspark.sql.functions import col, expr, when, lit
df = sc.parallelize([
("orange", "apple"), ("kiwi", None), (None, "banana"),
("mango", "mango"), (None, None)
]).toDF(["fruit1", "fruit2"])
profileId = "some value"
display(df.withColumn("ProfileId", lit(profileId)))