我還處于學習階段python。在以下示例中(取自本文的方法 3),用戶定義函式 (UDF) 的名稱為Total(...,...)。但作者是用名字來稱呼它的new_f(...,...)。
問題:在下面的代碼中,我們如何知道函式呼叫new_f(...,...)應該呼叫函式Total(...,...)?如果有另一個 UDF 函式,比如Sum(...,...). 在這種情況下,代碼如何知道 callnew_f(...,...)是指呼叫Total(...,...)還是Sum(...,...)?
# import the functions as F from pyspark.sql
import pyspark.sql.functions as F
from pyspark.sql.types import IntegerType
# define the sum_col
def Total(Course_Fees, Discount):
res = Course_Fees - Discount
return res
# integer datatype is defined
new_f = F.udf(Total, IntegerType())
# calling and creating the new
# col as udf_method_sum
new_df = df.withColumn(
"Total_price", new_f("Course_Fees", "Discount"))
# Showing the Dataframe
new_df.show()
uj5u.com熱心網友回復:
new_f = F.udf(Total, IntegerType())
將名稱 new_f 分配給該用戶定義的函式
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/479938.html
上一篇:如何根據其他值洗掉冗余值?
