这是我正在尝试做的事情:
- 我将数据读入scala
- 提取几列
- 使用 JEP 将创建的数据帧传递给 Python 脚本
- Python 脚本将数据帧转换为 pandas 执行一些操作并将其返回
但是我不确定如何将数据框传递给 python 脚本。这是python脚本(这只是示例脚本,而不是实际脚本):
import findspark
findspark.init()
import pandas as pd
#from pyspark.sql import types.*
from pyspark.sql import DataFrame as dataframe
def tes(df: dataframe):
df = df.toPandas()
df['concatenate'] = df['country'] + df['datasourceProvidedCountry']
return dataframe(df)
它一直失败并出现以下错误:
jep.JepException: <class 'ImportError'>: py4j.protocol
at /usr/local/lib64/python3.6/site-packages/jep/java_import_hook.__getattr__(java_import_hook.py:57)
at /home/hadoop/testpy.<module>(testpy.py:5)
at jep.Jep.run(Native Method)
at jep.Jep.runScript(Jep.java:359)
at jep.Jep.runScript(Jep.java:335)
... 49 elided
Caused by: java.lang.ClassNotFoundException: py4j.protocol
at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 52 more
spark-shell --conf spark.driver.extraLibraryPath=:/usr/local/lib64/python3.6/site-packages/jep:/usr/local/lib/python3.6/site-packages/py4j/ --jars /home/hadoop/jep-3.8.2.jar
谁能建议我如何使用 Jep 将数据帧从 scala 传递到 pyspark (如果这是重复的,请指向正确的线程,因为我找不到)?