I'm running this script with spark 2.4.3 & python 3.6.10
columns = ["language","users_count"]
data = [("Java", "20000"), ("Python", "100000"), ("Scala", "3000")]
spark = SparkSession.builder.appName('SparkByExamples.com').getOrCreate()
rdd = spark.sparkContext.parallelize(data)
df = rdd.toDF()
print(df.schema.toDDL)
AttributeError: 'StructType' object has no attribute 'toDDL'
The java documentation mentions that toDDL
function is available from spark 2.4.0, which is not in the python documentation.
Is there any other way to use this java function from python?
You can call the toDDL
method on the Java dataframe object:
df._jdf.schema().toDDL()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With