Complete the code to create a schema with a string field named 'name'.
from pyspark.sql.types import StructType, StructField, [1] schema = StructType([StructField('name', [1](), True)])
The StringType is used to define a string field in the schema.
Complete the code to validate a DataFrame against the schema.
df = spark.createDataFrame(data, schema=[1])The schema parameter is used to apply the schema when creating a DataFrame.
Fix the error in the code to import the correct type for an integer field.
from pyspark.sql.types import StructType, StructField, [1] schema = StructType([StructField('age', IntegerType(), True)])
The correct Spark SQL type for integers is IntegerType.
Fill both blanks to create a schema with a string field 'city' and an integer field 'population'.
schema = StructType([
StructField('city', [1](), True),
StructField('population', [2](), True)
])Use StringType for 'city' and IntegerType for 'population'.
Fill all three blanks to create a schema with fields: 'id' (integer), 'name' (string), and 'active' (boolean).
schema = StructType([
StructField('id', [1](), True),
StructField('name', [2](), True),
StructField('active', [3](), True)
])Use IntegerType for 'id', StringType for 'name', and BooleanType for 'active'.
