python - GCP 中的 PySpark 内核 - Unicode 字符串
问题描述
我有一个包含字符串的列的数据框。当我调用函数时:
df = spark.read.csv(path, header=True).show()
我得到正确的“视图”,但是当我打印时
print("dataframe as a RDD object (list of Row objects):\n\t", df.collect())
结果是带有 unicode 符号的字符串,例如u'mystring'
我怎样才能解决这个问题
解决方案
在 Python 2.x 中,您拥有str
和unicode
. 周围的对象u'mytext'
是 Unicode。
要将 unicode 转换为 str:
mystr = unistr.encode('utf-8')
要将 str 转换为 unicode:
unistr = mystr.decode('utf-8')
在 Python 2.x 中,我通常将字符串保留为 Unicode,直到需要将它们写入文件等。在 Python 3.x 中,所有字符串都是 Unicode。
以下文档将有助于理解:
推荐阅读
- excel - 根据列中的 Yes/No 值在新行中生成连接文本。VBA 按钮宏
- java - javax.servlet.ServletException: java.lang.NoSuchMethodError 有人可以帮忙解决这个问题
- r - 如何使用不同的几何图形将边际总计添加到 ggplot2 facet_grid 图
- c# - 检查大写和小写字母 C#
- ruby-on-rails - 如何将 Rails 应用程序连接到主机上的 docker postgres
- python - Python:从 yaml_file1 中的嵌套字典中提取密钥对值并将密钥对放入 yaml_file2
- javascript - 如何在 React 中输入格式化模板
- google-calendar-api - 使 Google 日历可从特定网站读取/写入
- firebase - 子集合中的相同文档 ID 是否会导致 Firestore 中的热点?
- reactjs - React 主页上的搜索栏以重定向到结果页面