Reputation: 10153
Why this is working just fine
from pyspark.sql.types import *
l=[("foo",83.33)]
schema = StructType([
StructField("type", StringType(), True),
StructField("value", DoubleType(), True)])
df= spark.createDataFrame(l,schema)
And this
l=[(83.33)]
schema = StructType([
StructField("value", DoubleType(), True)])
df= spark.createDataFrame(l,schema)
Gives me an error
StructType can not accept object 83.33 in type <class 'float'>
Upvotes: 2
Views: 9607
Reputation: 11274
When using a one element tuple, a trailing comma is required. Check this TupleSyntax
>>> l=[(83.33,)] //note the comma (,)
>>> schema = StructType([
... StructField("value", DoubleType(), True)])
>>> df= spark.createDataFrame(l,schema)
>>> df.show()
+-----+
|value|
+-----+
|83.33|
+-----+
Upvotes: 7