我有一个用户自定义函数:
calc = udf(calculate, FloatType())
param1 = "A"
result = df.withColumn('col1', calc(col('type'), col('pos'))).groupBy('pk').sum('events')
def calculate(type, pos):
if param1=="A":
a, b = [ 0.05, -0.06 ]
else:
a, b = [ 0.15, -0.16 ]
return a * math.pow(type, b) * max(pos, 1)
我需要向这个 udf
传递一个参数 param1
。我该怎么做?
def calculate(type, pos):
。你的意思是需要看完整的函数吗? - Dinosaurius