I have the following PySpark dataframe:
df = spark.createDataFrame(
[
('31,2', 'foo'),
('33,1', 'bar'),
],
['cost', 'label']
)
I need to cast the ´cost´ column to float. I do it as follows:
df = df.withColumn('cost', df.cost.cast('float'))
However, as I result I get null values instead of numbers in the cost column.
How can I convert cost to float numbers?
regex_replacefunction. spark.apache.org/docs/3.1.1/api/python/reference/api/…