How to get the schema definition from a dataframe in PySpark?

前端 未结 4 2056
萌比男神i
萌比男神i 2021-02-12 14:25

In PySpark it you can define a schema and read data sources with this pre-defined schema, e. g.:

Schema = StructType([ Str         


        
4条回答
  •  我寻月下人不归
    2021-02-12 14:52

    Yes it is possible. Use DataFrame.schema property

    schema

    Returns the schema of this DataFrame as a pyspark.sql.types.StructType.

    >>> df.schema
    StructType(List(StructField(age,IntegerType,true),StructField(name,StringType,true)))
    

    New in version 1.3.

    Schema can be also exported to JSON and imported back if needed.

提交回复
热议问题