apache-spark - 将 SequenceFile 转换为 DataFrame
问题描述
我有一个 SequenceFile,我想使用 Pyspark 将其转换为 DataFrame。
为此,我使用以下代码:
seq_file = sc.sequenceFile("products_sequencefile")
df = prod_seq.map(lambda a: str(a).split(",")).map(lambda a: (a[0],a[1],a[2],a[3],a[4],a[5],a[6])).toDF()
但是,它给了我一个带有 'u:
+--------+-------+---+--------------------+---+------+--------------------+
| _1| _2| _3| _4| _5| _6| _7|
+--------+-------+---+--------------------+---+------+--------------------+
|(u'1009'| u'1009| 45|Diamond Fear No E...| |599.99|http://images.acm...|
我在做正确的方法吗?
解决方案
直接用toDF试试?
df = sc.sequenceFile("products_sequencefile").toDF('key', 'value')
ncols = 6 # set the ncols here as appropriate
df = df.select(
'key',
*[F.split(F.col('value'), ',')[i] for i in range(ncols)]
)
推荐阅读
- asp.net-core - .Net Core 标记助手智能感知不起作用
- r - 如何使用 roll_lm 函数对多个自变量进行滚动回归
- office-js - Office.Settings 存储上限是多少?
- swiftui - 如何导航到 SwiftUI 设置的新视图
- nexmo - nexmo 用户:创建在 Nexmo-cil 中不起作用
- laravel - 如何在 laravel/octobercms 和 twig 中按 Id 显示星级?
- python - 像从我的浏览器一样导航网页(Python、selenium)
- node.js - 在 Nodejs (with express js) 项目的 ejs 文件中添加 Font Awesome 图标
- ios - iOS 的 Flutter 风格在运行时会出现 SharedPreference 错误
- javascript - 提及检测不和谐机器人javascript的问题