[英]Read TSV file in pyspark
What is the best way to read.tsv file with header in pyspark and store it in a spark data frame.在 pyspark 中使用 header 读取 .tsv 文件并将其存储在 spark 数据框中的最佳方法是什么。
I am trying to use "spark.read.options" and "spark.read.csv" commands however no luck.我正在尝试使用“spark.read.options”和“spark.read.csv”命令但是没有运气。
Thanks.谢谢。
Regards, Jit问候, 吉特
Well you can directly read the tsv file without providing external schema if there is header available as:如果有 header 可用,您可以直接读取 tsv 文件而不提供外部模式:
df = spark.read.csv(path, sep=r'\t', header=True).select('col1','col2')
Since spark is lazily evaluated it'll read only selected columns.由于 spark 被懒惰地评估,它只会读取选定的列。 Hope it helps.
希望能帮助到你。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.