我有一个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...|我做的是正确的方法吗?
发布于 2020-12-12 18:43:14
尝试直接使用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)]
)https://stackoverflow.com/questions/65263943
复制相似问题