How to read data from file system (csv, json, etc) to DataFrame


What I have found from googling are mostly about loading data from hdfs into dataframe, I wonder what’s the best practice to load data from file system.

For RDD, I know I can do this way:
val productsRaw ="/data/retail_db/products/part-00000")

For DataFrame, how do I write my code?

Thank you very much.



After your above step, create RDD then convert your RDD into DF using .toDF()


You can read a text file to create a dataframe path)