schéma (datový rámec)

Vrátí schéma tohoto DataFrame typu .StructType

Návraty

StructType

Příklady

Načtěte odvozené schéma aktuálního datového rámce.

df = spark.createDataFrame(
    [(14, "Tom"), (23, "Alice"), (16, "Bob")], ["age", "name"])
df.schema
# StructType([StructField('age', LongType(), True),
#             StructField('name', StringType(), True)])

Načtěte schéma aktuálního datového rámce z řetězce schématu ve formátu DDL.

df = spark.createDataFrame(
    [(14, "Tom"), (23, "Alice"), (16, "Bob")],
    "age INT, name STRING")
df.schema
# StructType([StructField('age', IntegerType(), True),
#             StructField('name', StringType(), True)])

Načtěte zadané schéma aktuálního datového rámce.

from pyspark.sql.types import StructType, StructField, StringType
df = spark.createDataFrame(
    [("a",), ("b",), ("c",)],
    StructType([StructField("value", StringType(), False)]))
df.schema
# StructType([StructField('value', StringType(), False)])