我try 了以下代码,但不起作用:
df=df.withColumn("cars", typedLit(Map.empty[String, String]))
给出错误:NameError: name 'typedLit' is not defined
我try 了以下代码,但不起作用:
df=df.withColumn("cars", typedLit(Map.empty[String, String]))
给出错误:NameError: name 'typedLit' is not defined
创建一个空列并将其转换为所需的类型.
from pyspark.sql import functions as F, types as T
df = df.withColumn("cars", F.lit(None).cast(T.MapType(T.StringType(), T.StringType())))
df.select("cars").printSchema()
root
|-- cars: map (nullable = true)
| |-- key: string
| |-- value: string (valueContainsNull = true)