This tutorial will explain how to read various types of comma separate(CSV) files or other delimited files into Spark dataframe.

PySpark: File To Dataframe(Part 1)

This tutorial will explain how to read various types of comma separated value(CSV) files or other delimited files into Spark dataframe.


➠ Read CSV file(without header): Users can click here to download file used in the these examples.

➠ CSV file(with header): Spark provides a way to read header columns as name from a file using either option() or options() functions. Options function is used in the below example. Users can click here to download file used in this example.

➠ Read Delimited file: Although CSV files are also delimited files, these examples are separately mentioned here to read delimited files with customized separator i.e delimiter other than comma(,).
➠ Read CSV from HDFS: Spark can also read data from HDFS system. As such there is no syntax difference in reading from Local or HDFS, only difference will be the path difference.

➠ Read Multiple CSV Files: Users can click here(File 1) and here(File 2) to download files used in these example.