pyspark - Pyspark:转换/转换为数字类型
问题描述
我有这个方法,我需要将参数从字符串转换为数字才能操作:
df = (df.withColumn('distance', dist_fast('LOCLAT', 'LOCLONG', 'LOCLAT2', 'LOCLONG2')))
我会很感激一些帮助
非常感谢
解决方案
如下正确使用方法链接,这应该转换为整数类型
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())
推荐阅读
- javascript - 我可以从 Wordpress 数据库中获取 React 应用程序的用户密码吗?
- c++ - 将 Rcpp 的 as/wrap 函数放在哪里?
- java - JavaFX 预加载器问题
- c# - 在 DataGridView 底部添加行时出现问题
- c - 传递数组名称时 sizeof 如何工作
- java - springboot-aop 无法获取 joinPoint 参数的类对象
- google-api - 带有同义词的谷歌翻译 API
- amazon-web-services - AWS APi Gateway VPC LINK - 确保您传递的是 Gzip 流
- java - 如何在可用的詹金斯奴隶上平均分配测试?
- python - numpy中deg2rad和弧度之间的区别?