在 Spark 中使用 Pandas
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41809308/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use pandas with Spark
提问by Zop
I have a Noob Question on spark and pandas. I would like to use pandas, numpy etc.. with spark but when i import a lib i have an error. can you help me plz? This is my code
我有一个关于 spark 和 pandas 的菜鸟问题。我想在 spark 中使用 pandas、numpy 等,但是当我导入 lib 时出现错误。你能帮我吗?这是我的代码
from pyspark import SparkContext, SQLContext
from pyspark import SparkConf
import pandas
# Config
conf = SparkConf().setAppName("Script")
sc = SparkContext(conf=conf)
log4j = sc._jvm.org.apache.log4j
log4j.LogManager.getRootLogger().setLevel(log4j.Level.ERROR)
sqlCtx = SQLContext(sc)
# Importation of csv out of HDFS
data_name = "file_on_hdfs.csv"
data_textfile = sc.textFile(data_name)
This is the error:
这是错误:
ImportError: No module named pandas
How can i use pandas? It's not a local mode.
我如何使用Pandas?这不是本地模式。
回答by AndreyF
回答by Beyhan Gül
回答by Abu Tahir
Check whether you have pandas installed in your box with pip list|grep 'pandas'
command in a terminal.If you have a match then do a apt-get update
.
If you are using multi node cluster , yes you need to install pandas in all the client box.
pip list|grep 'pandas'
使用终端中的命令检查您的盒子中是否安装了 Pandas。如果您有匹配项,则执行apt-get update
. 如果您使用的是多节点集群,是的,您需要在所有客户端中安装 Pandas。
Better to try spark version of DataFrame, but if you still like to use pandas the above method would work
最好尝试 Spark 版本的 DataFrame,但如果您仍然喜欢使用 Pandas,则上述方法会起作用