[英]StructType can not accept object float in pyspark
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'>
When using a one element tuple, a trailing comma is required. 使用单元素元组时,需要使用尾随逗号。 Check this TupleSyntax 检查这个TupleSyntax
>>> l=[(83.33,)] //note the comma (,)
>>> schema = StructType([
... StructField("value", DoubleType(), True)])
>>> df= spark.createDataFrame(l,schema)
>>> df.show()
+-----+
|value|
+-----+
|83.33|
+-----+
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.