首页 > 解决方案 > Pyspark:转换/转换为数字类型

问题描述

我有这个方法,我需要将参数从字符串转换为数字才能操作:

df = (df.withColumn('distance', dist_fast('LOCLAT', 'LOCLONG', 'LOCLAT2', 'LOCLONG2')))

我会很感激一些帮助

非常感谢

标签: pyspark

解决方案


如下正确使用方法链接,这应该转换为整数类型

df = df.withColumn('LOCLAT', F.col("LOCLAT).cast(T.IntegerType()).withColumn('LOCLONG', F.col("LOCLONG).cast(T.IntegerType()).withColumn('LOCLAT2', F.col("LOCLAT2).cast(T.IntegerType()).withColumn('LOCLONG2', F.col("LOCLONG2).cast(T.IntegerType())

推荐阅读