![](/img/trans.png)
[英]How to run Regex in Python on a Dataframe in Apache Spark
[英]Column is not iterable - apache spark dataframe - python
一种可能的解决方案:
from pyspark.sql.functions import expr
df = spark.createDataFrame(["9.5%", "7.0%"], "string").toDF("int_rate")
df.withColumn("int_rate", expr("rtrim('%', int_rate)").cast("float")).show()
还有另一个
from pyspark.sql.functions import regexp_replace
df.withColumn("int_rate", regexp_replace("int_rate", "%$", "").cast("float"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.