pyspark.sql.functions.schema_of_csv(csv: ColumnOrName, options: Optional[Dict[str, str]] = None) → pyspark.sql.column.Column

Parses a CSV string and infers its schema in DDL format.

csvColumn or str

a CSV string or a foldable string column containing a CSV string.

optionsdict, optional

options to control parsing. accepts the same options as the CSV datasource. See Data Source Option in the version you use.


>>> df = spark.range(1)
>>>'1|a'), {'sep':'|'}).alias("csv")).collect()
[Row(csv='STRUCT<_c0: INT, _c1: STRING>')]
>>>'1|a', {'sep':'|'}).alias("csv")).collect()
[Row(csv='STRUCT<_c0: INT, _c1: STRING>')]