首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >熊猫UDF不比星火UDF快吗?

熊猫UDF不比星火UDF快吗?
EN

Stack Overflow用户
提问于 2020-05-12 19:23:46
回答 1查看 5.5K关注 0票数 3

我把下面的UDF从派克的网站,因为我试图了解,如果有一个性能改善。我做了大量的数字,但两者的时间几乎相同,我做错了什么?

谢谢!

代码语言:javascript
复制
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

代码语言:javascript
复制
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
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-05-12 19:43:48

除非您的数据足够大,以至于它不能仅由一个节点处理,否则不应该考虑。

熊猫在单个节点上执行所有操作,而spark则将数据分配给多个节点进行处理。

因此,如果你在一小部分数据上进行比较,熊猫的表现可能会好于火花。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/61760247

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档