既然我是Pyspark的初学者,那么有人可以帮助将整数列转换为字符串吗?
这是我在Aws Athena中的代码,我需要将其转换为pyspark数据框。
case when A.[HHs Reach] = 0 or A.[HHs Reach] is null then '0'
when A.[HHs Reach] = 1000000000 then '*'
else cast(A.[HHs Reach] as varchar) end as [HHs Reach]
答案 0 :(得分:0)
假设df是您的数据帧,如下所示:
from pyspark.sql import functions as F
df.withColumn(
"HHs Reach",
F.when(F.col("HHs Reach").isNull(), '0')
.when(F.col("HHs Reach") == 1000000000, '*')
.otherwise(F.col("HHs Reach").cast("string"))
)