Building a StructType from a dataframe in pyspark

后端 未结 4 1021
后悔当初
后悔当初 2021-02-04 06:45

I am new spark and python and facing this difficulty of building a schema from a metadata file that can be applied to my data file. Scenario: Metadata File for the Data file(csv

4条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-04 07:19

    The attribute df.schema of a pyspark DataFrame return the StructType.

    Given your df:

    +--------------------+---------------+
    |                name|           type|
    +--------------------+---------------+
    |                  id|  IntegerType()|
    |          created_at|TimestampType()|
    |          updated_at|   StringType()|
    

    Type:

    df.schema
    

    Result:

    StructType(
     List(
      StructField(id,IntegerType,true),
      StructField(created_at,TimestampType,true),
      StructField(updated_at,StringType,true)
     )
    

提交回复
热议问题