将数据框架构从 int 更改为 double 时出现问题
Issue in changing the dataframe schema from int to double
我有一个数据框标签,我想将数据框的架构从整数更改为双精度
数据框的模式是
label.printSchema
root
|-- value: integer (nullable = false)
我使用的命令是
label = label.withColumn('value', label.value.cast('double'))
我收到的错误是:
error: unclosed character literal
from pyspark.sql.types import DoubleType,IntegerType
cSchema = StructType([StructField("value",IntegerType())])
test_list = [[1],[2]]
df = spark.createDataFrame(test_list,schema=cSchema)
df.printSchema()
castedDF = df.withColumn("value", df["value"].cast("double"))
castedDF.printSchema()
castedDF.show()
而且,输出是(如预期的那样)
root
|-- value: integer (nullable = true)
root
|-- value: double (nullable = true)
+-----+
|value|
+-----+
| 1.0|
| 2.0|
+-----+
label = label.withColumn("value", label("value").cast(DoubleType))
我有一个数据框标签,我想将数据框的架构从整数更改为双精度
数据框的模式是
label.printSchema
root
|-- value: integer (nullable = false)
我使用的命令是
label = label.withColumn('value', label.value.cast('double'))
我收到的错误是:
error: unclosed character literal
from pyspark.sql.types import DoubleType,IntegerType
cSchema = StructType([StructField("value",IntegerType())])
test_list = [[1],[2]]
df = spark.createDataFrame(test_list,schema=cSchema)
df.printSchema()
castedDF = df.withColumn("value", df["value"].cast("double"))
castedDF.printSchema()
castedDF.show()
而且,输出是(如预期的那样)
root
|-- value: integer (nullable = true)
root
|-- value: double (nullable = true)
+-----+
|value|
+-----+
| 1.0|
| 2.0|
+-----+
label = label.withColumn("value", label("value").cast(DoubleType))