如何从星火CSV文件中跳过标题? [英] How to skip header from csv files in Spark?

查看:178
本文介绍了如何从星火CSV文件中跳过标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我举三个文件的路径引发的上下文来读取每个文件在第一行的模式。我们如何能够跳过从标题的模式行

Suppose I give three files paths to spark context to read and each file has schema in first row. how can we skip schema lines from headers

val rdd=sc.textFile("file1,file2,file3")

现在我们如何能够从这个RDD跳过标题行?

now how can we skip header lines from this rdd?

推荐答案

您可以单独加载每个文件,用过滤它们file.zipWithIndex()进行筛选。(_._ 2 0),然后联合所有的文件RDDS。

You could load each file separately, filter them with file.zipWithIndex().filter(_._2 > 0) and then union all the file RDDs.

如果文件的数量太大,工会可能会抛出一个 StackOverflowExeption

If the number of files is too large, the union could throw a StackOverflowExeption.

这篇关于如何从星火CSV文件中跳过标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆