在 pyspark 中使用 pandas_udf 中的外部库 [英] Use external library in pandas_udf in pyspark
本文介绍了在 pyspark 中使用 pandas_udf 中的外部库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以在 pandas_udf 中使用像 textdistance 这样的外部库?我已经尝试过,但出现此错误:
It's possible to use a external library like textdistance inside pandas_udf? I have tried and I get this error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
我已尝试使用 Spark 2.3.1 版.
I have tried with Spark version 2.3.1.
推荐答案
你可以将 textdistance
和你自己的代码打包在一起(使用 setup.py 和 bdist_egg
来构建egg
文件),并在运行 spark 时使用选项 --py-files
指定最终包.
You can package the textdistance
together with your own code (use setup.py and bdist_egg
to build an egg
file), and specify the final package with option --py-files
while you run spark.
顺便说一句,错误信息似乎与 textdistance
完全没有关系.
btw, the error message doesn't seem to relate with textdistance
at all.
这篇关于在 pyspark 中使用 pandas_udf 中的外部库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文