我把下面的UDF从派克的网站,因为我试图了解,如果有一个性能改善。我做了大量的数字,但两者的时间几乎相同,我做错了什么?
谢谢!
import pandas as pd
from pyspark.sql.functions import col, udf
from pyspark.sql.types import LongType
import time
start = time.time()
# Declare the function and create the UDF
def multiply_func(a, b):
return a * b
multiply = udf(multiply_func, returnType=LongType())
# The function for a pandas_udf should be able to execute with local Pandas data
x = pd.Series(list(range(1, 1000000)))
print(multiply_func(x, x))
# 0 1
# 1 4
# 2 9
# dtype: int64
end = time.time()
print(end-start)这是潘达斯的UDF
import pandas as pd
from pyspark.sql.functions import col, pandas_udf
from pyspark.sql.types import LongType
import time
start = time.time()
# Declare the function and create the UDF
def multiply_func(a, b):
return a * b
multiply = pandas_udf(multiply_func, returnType=LongType())
# The function for a pandas_udf should be able to execute with local Pandas data
x = pd.Series(list(range(1, 1000000)))
print(multiply_func(x, x))
# 0 1
# 1 4
# 2 9
# dtype: int64发布于 2020-05-12 19:43:48
除非您的数据足够大,以至于它不能仅由一个节点处理,否则不应该考虑。
熊猫在单个节点上执行所有操作,而spark则将数据分配给多个节点进行处理。
因此,如果你在一小部分数据上进行比较,熊猫的表现可能会好于火花。
https://stackoverflow.com/questions/61760247
复制相似问题