Apache spark 火花更换柱类型失败
我有Spark提供的上述数据模式。我正在尝试将dt中的类型timestamp更改为stringApache spark 火花更换柱类型失败,apache-spark,pyspark,apache-spark-sql,Apache Spark,Pyspark,Apache Spark Sql,我有Spark提供的上述数据模式。我正在尝试将dt中的类型timestamp更改为string root |-- dt: timestamp (nullable = true) |-- AverageTemperature: double (nullable = true) |-- AverageTemperatureUncertainty: double (nullable = true) |-- City: string (nullable = true) |-- Country:
root
|-- dt: timestamp (nullable = true)
|-- AverageTemperature: double (nullable = true)
|-- AverageTemperatureUncertainty: double (nullable = true)
|-- City: string (nullable = true)
|-- Country: string (nullable = true)
|-- Latitude: string (nullable = true)
|-- Longitude: string (nullable = true)
这就是我所做的,我得到了以下错误:
temperature_df.withColumn("dt",col("dt").cast(StringType()))
有人能给我解释一下为什么我会出现这个错误吗?我相信这应该是可行的(请确保从
pyspark.sql.types导入StringType
:
TypeError: 'list' object is not callable
我相信这应该可以(确保从
pyspark.sql.types
导入StringType):
TypeError: 'list' object is not callable
在哪一行您有这个错误,您可以共享导致这个问题的代码吗?因为根据您共享的行和模式,我看不出这个错误的可能原因,否则您的代码中有没有名为col的对象?
temperature\u df.withColumn(“dt”,col(“dt”).cast(StringType())
这是这一行。不,我没有任何名为col的对象。在哪一行您有该错误,您能否共享导致该问题的代码,因为根据您共享的行和架构,我看不出该错误的可能原因,否则您的代码中有任何名为col的对象吗?带列(“dt”,col(“dt”).cast的温度(StringType())
这是行。不,我没有任何名为col的对象。
from pyspark.sql import functions as f
from pyspark.sql.types import StringType
temperature_df.withColumn("dt",f.col("dt").cast(StringType()))