简体   繁体   English

StructType不能接受pyspark中的对象浮点数

[英]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.

相关问题 PySpark:TypeError:StructType不能接受类型为0.10000000000000001的对象<type 'numpy.float64'> - PySpark: TypeError: StructType can not accept object 0.10000000000000001 in type <type 'numpy.float64'> PySpark错误:StructType不能接受类型为0的对象<type 'int'> - PySpark Error: StructType can not accept object 0 in type <type 'int'> PySpark:TypeError:StructType不能接受类型的对象 <type 'unicode'> 要么 <type 'str'> - PySpark: TypeError: StructType can not accept object in type <type 'unicode'> or <type 'str'> Spark Sql: TypeError(“StructType 不能接受 %s 类型的对象”% type(obj)) - Spark Sql: TypeError(“StructType can not accept object in type %s” % type(obj)) 获取TypeError(“StructType不能接受类型%s中的对象%r”%(obj,type(obj))) - Getting TypeError(“StructType can not accept object %r in type %s” % (obj, type(obj))) Pyspark 将 StructType 转换为 ArrayType<StructType> - Pyspark Cast StructType as ArrayType<StructType> Pyspark模式中StructType的VectorType - VectorType for StructType in Pyspark Schema Pyspark StructType 未定义 - Pyspark StructType is not defined pyspark:TypeError:IntegerType不能接受类型中的对象<type 'unicode'> - pyspark: TypeError: IntegerType can not accept object in type <type 'unicode'> Pyspark DataframeType error a: DoubleType can not accept object 'a' in type<class 'str'></class> - Pyspark DataframeType error a: DoubleType can not accept object 'a' in type <class 'str'>
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM