加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – PySpark – UnicodeEncodeError:’ascii’编解码

发布时间:2020-12-17 00:51:36 所属栏目:Python 来源:网络整理
导读:使用spark.read.csv将带有外来字符(???)的数据框加载到Spark中,并使用encoding =utf-8并尝试执行简单的show(). df.show()Traceback (most recent call last):File " 我认为这可能与Python本身有关但我无法理解here for example中提到的任何技巧如何应用于PyS

使用spark.read.csv将带有外来字符(???)的数据框加载到Spark中,并使用encoding =’utf-8’并尝试执行简单的show().

>>> df.show()

Traceback (most recent call last):
File "

我认为这可能与Python本身有关但我无法理解here for example中提到的任何技巧如何应用于PySpark和show() – 函数的上下文中.

最佳答案
https://issues.apache.org/jira/browse/SPARK-11772讨论了这个问题并提供了一个运行解决方案:

export PYTHONIOENCODING=utf8

在跑pyspark之前.我想知道为什么以上工作,因为即使没有它,sys.getdefaultencoding()也为我返回了utf-8.

How to set sys.stdout encoding in Python 3?还谈到了这一点,并为Python 3提供了以下解决方案:

import sys
sys.stdout = open(sys.stdout.fileno(),mode='w',encoding='utf8',buffering=1)

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读