自定义定界符CSV阅读器Spark

编程入门 行业动态 更新时间:2024-10-10 04:24:27
本文介绍了自定义定界符CSV阅读器Spark的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我想使用Apache Spark读取具有以下结构的文件.

I would like to read in a file with the following structure with Apache Spark.

628344092\t20070220\t200702\t2007\t2007.1370

定界符为\ t.在使用spark.read.csv()时如何实现呢?

The delimiter is \t. How can I implement this while using spark.read.csv()?

csv太大了,无法使用熊猫,因为它需要很长时间才能读取此文件.是否有某种类似于

The csv is much too big to use pandas because it takes ages to read this file. Is there some way which works similar to

pandas.read_csv(file, sep = '\t')

非常感谢!

推荐答案

使用spark.read.option("delimiter", "\t").csv(file)或sep代替delimiter.

如果字面上是\t,而不是制表符特殊字符,请使用双精度\:spark.read.option("delimiter", "\\t").csv(file)

If it's literally \t, not tab special character, use double \: spark.read.option("delimiter", "\\t").csv(file)

更多推荐

自定义定界符CSV阅读器Spark

本文发布于:2023-11-13 02:34:06,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1583182.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   阅读器   定界   CSV   Spark

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!