简体   繁体   English

PySpark:TypeError:StructType不能接受类型为0.10000000000000001的对象<type 'numpy.float64'>

[英]PySpark: TypeError: StructType can not accept object 0.10000000000000001 in type <type 'numpy.float64'>

when using PySpark with the following code: 使用带有以下代码的PySpark时:

from pyspark.sql.types import *
samples = np.array([0.1,0.2])
dfSchema = StructType([StructField("x", FloatType(), True)])
spark.createDataFrame(samples,dfSchema)

I get: 我得到:

TypeError: StructType can not accept object 0.10000000000000001 in type type 'numpy.float64'> TypeError:StructType无法接受类型为'numpy.float64'的对象0.10000000000000001>

Any idea? 任何想法?

NumPy types, including numpy.float64 , are not a valid external representation for Spark SQL types. NumPy类型(包括numpy.float64 )不是Spark SQL类型的有效外部表示形式。 Furthermore schema you use doesn't reflect the shape of the data. 此外,您使用的架构不会反映数据的形状。

You should use standard Python types, and corresponding DataType directly: 您应该直接使用标准Python类型和相应的DataType

spark.createDataFrame(samples.tolist(), FloatType()).toDF("x")

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TypeError:类型为“ numpy.float64”的对象没有len() - TypeError: object of type 'numpy.float64' has no len() TypeError:^:'numpy.float64'和'numpy.float64'的不支持的操作数类型 - TypeError: unsupported operand type(s) for ^: 'numpy.float64' and 'numpy.float64' PySpark:TypeError:StructType不能接受类型的对象 <type 'unicode'> 要么 <type 'str'> - PySpark: TypeError: StructType can not accept object in type <type 'unicode'> or <type 'str'> 引发 TypeError (TypeError: object of type<class 'numpy.float64'> 不能安全地解释为整数) - Raise TypeError (TypeError: object of type <class 'numpy.float64'> cannot be safely interpreted as an integer) PySpark错误:StructType不能接受类型为0的对象<type 'int'> - PySpark Error: StructType can not accept object 0 in type <type 'int'> 为什么会发生TypeError:类型为&#39;numpy.float64&#39;的对象没有len() - Why occur TypeError: object of type 'numpy.float64' has no len() TypeError:类型为&#39;numpy.float64&#39;的对象在赋值矩阵元素时没有len() - TypeError: object of type 'numpy.float64' has no len() on assignment of matrix element 类型错误有什么问题:TypeError: 'numpy.float64' object 不能解释为 integer - What is the problem with the type error: TypeError: 'numpy.float64' object cannot be interpreted as an integer TypeError: &#39;numpy.float64&#39; 类型的对象在打印数据帧中第一列的回归系数时没有 len() - TypeError: object of type 'numpy.float64' has no len() when printing the regression coefficient of the first column in dataframe for i in range(len(val)): TypeError: object of type 'numpy.float64' has no len() - for i in range(len(val)): TypeError: object of type 'numpy.float64' has no len()
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM