I'd like to convert a float to a currency using Babel and PySpark
sample data:
amount currency
2129.9 RON
1700 EUR
1268 GBP
741.2 USD
142.08091153 EUR
4.7E7 USD
0 GBP
I tried:
df = df.withColumn(F.col('amount'), format_currency(F.col('amount'), F.col('currency'),locale='be_BE'))
or
df = df.withColumn(F.col('amount'), format_currency(F.col('amount'), 'EUR',locale='be_BE'))

amountcolumn and also since the error is because of the decimal conversion so you can check check if there is any/in the entire column ofamount.amountcolumn apart fromnumeric? As there is no other reason why it will have adecimal conversionerrorEin the column e.g.4.7E7numeric or integeror not, you can usedf.select("amount",F.col("amount").cast("int").isNotNull().alias("Truth")).show()regexp_extract?