def di(l1,l2, ln1, ln2):
dlt = (l2-l1)
dln = (ln2-ln1)
d = dlt * dln
return d
abc = newdf[['l1','l2','ln1','ln2']]
abc.columns
Function working without errors. But while working on dataframe, it showing error as
di() missing 2 required positional arguments: ln1, ln2
newdf = newdf.withColumn('newcolnm',reduce(di, ( newdf[col] for col in abc.columns ) ))
Your function definition is correct but when calling the function you arent passing requited 4 arguments. your calling should be like funct(a, b, c, d)
if you don't want parameters compulsory define your function as
di (p1=None, p2=None, p3=None, p4=None)
with this you can omit unwanted parameters
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.