DataFrameReader.
csv
Loads a CSV file and returns the result as a DataFrame.
DataFrame
This function will go through the input once to determine the input schema if inferSchema is enabled. To avoid going through the entire data once, disable inferSchema option or specify the schema explicitly using schema.
inferSchema
schema
New in version 2.0.0.
string, or list of strings, for input path(s), or RDD of Strings storing CSV rows.
pyspark.sql.types.StructType
an optional pyspark.sql.types.StructType for the input schema or a DDL-formatted string (For example col0 INT, col1 DOUBLE).
col0 INT, col1 DOUBLE
For the extra options, refer to Data Source Option in the version you use.
Examples
>>> df = spark.read.csv('python/test_support/sql/ages.csv') >>> df.dtypes [('_c0', 'string'), ('_c1', 'string')] >>> rdd = sc.textFile('python/test_support/sql/ages.csv') >>> df2 = spark.read.csv(rdd) >>> df2.dtypes [('_c0', 'string'), ('_c1', 'string')]