Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
130 views
in Technique[技术] by (71.8m points)

python - Driver stacktrace in PySpark

I am trying to do following steps

df1 = df.na.drop(subset=["Column1", "Column2", "Column3", "Column4", "Column5","Column6"])
df1 =  df1.withColumn('Column6',df1['Column6'].cast(DoubleType()))
udf_dict = udf(lambda x,y: 1 if(x>=y) else 0,IntegerType())
df1 = df1.withColumn('Flag',udf_dict('Column2','Column6'))
filter1 = df1.filter(df1['Flag'] == 1)

It is giving me following error

enter image description here enter image description here

Please suggest where it is going wrong

question from:https://stackoverflow.com/questions/65904090/driver-stacktrace-in-pyspark

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

There are nulls in your dataframe, which causes the UDF to fail. However, there is no need to use an UDF here. You can just filter the dataframe by comparing the two columns directly.

df1 = df.na.drop(subset=["Column1", "Column2", "Column3", "Column4", "Column5","Column6"])
df1 = df1.withColumn('Column6',df1['Column6'].cast(DoubleType()))
filter1 = df1.filter('Column2 >= Column6')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...