簡體   English   中英

StructType不能接受pyspark中的對象浮點數

[英]StructType can not accept object float in pyspark

為什么這個工作得很好

from pyspark.sql.types import *
l=[("foo",83.33)]
schema = StructType([
   StructField("type", StringType(), True),
   StructField("value", DoubleType(), True)])
df= spark.createDataFrame(l,schema)

和這個

 l=[(83.33)]
    schema = StructType([
    StructField("value", DoubleType(), True)])
    df= spark.createDataFrame(l,schema)

給我一個錯誤

StructType can not accept object 83.33 in type <class 'float'>

使用單元素元組時,需要使用尾隨逗號。 檢查這個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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM