如何解决DataFrame 显示字符串表示失败,showString(Integer, Boolean, Boolean) 不存在
我正在尝试按照建议的 here 捕获由 show()
函数生成的字符串表示,但似乎 showString
方法不再公开。
logger.info('\n{}'.format(raw_data._jdf.showString(20,False,False)))
正在返回以下错误跟踪
Traceback (most recent call last):
File "xxxxxxxx/SparkTest/main.py",line 63,in <module>
logger.info('\n{}\n'.format(raw_data._jdf.showString(20,False)))
File "xxxxxxxx/envs/SparkTest/lib/python3.8/site-packages/py4j/java_gateway.py",line 1304,in __call__
return_value = get_return_value(
File "xxxxxxxx/envs/SparkTest/lib/python3.8/site-packages/pyspark/sql/utils.py",line 128,in deco
return f(*a,**kw)
File "xxxxxxxx/envs/SparkTest/lib/python3.8/site-packages/py4j/protocol.py",line 330,in get_return_value
raise Py4JError(
py4j.protocol.Py4JError: An error occurred while calling o45.showString. Trace:
py4j.Py4JException: Method showString([class java.lang.Integer,class java.lang.Boolean,class java.lang.Boolean]) does not exist
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:318)
at py4j.reflection.ReflectionEngine.getMethod(ReflectionEngine.java:326)
at py4j.Gateway.invoke(Gateway.java:274)
at py4j.commands.AbstractCommand.invokeMethod(AbstractCommand.java:132)
at py4j.commands.CallCommand.execute(CallCommand.java:79)
at py4j.GatewayConnection.run(GatewayConnection.java:238)
at java.base/java.lang.Thread.run(Thread.java:832)
这种方法还有其他替代方法吗?
解决方法
错误表明方法 showString(Integer,Boolean,Boolean)
不存在。如果您查看 showString
源代码,它会将 Integer
作为第二个参数,但您传递的是 boolean
。
您想设置 truncate=False
,因此只需在第二个参数中传递 0:
logger.info('\n{}'.format(raw_data._jdf.showString(20,False)))
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。