Pyspark StructType is not defined

from pyspark.sql.types import StructType

That would fix it but next you might get NameError: name 'IntegerType' is not defined or NameError: name 'StringType' is not defined ..

To avoid all of that just do:

from pyspark.sql.types import *

Alternatively import all the types you require one by one:

from pyspark.sql.types import StructType, IntegerType, StringType

All Types: Apache Spark Data Types


Did you import StructType? If not

from pyspark.sql.types import StructType

should solve the problem.