'PySpark dataframe remove white-spaces from a column of the string

Here in this pic, column Values contains some string values where the spaces are there in between, hence I am unable to convert this column to an Integer type. If you can help me remove this white space from these string values, I can then cast them easily. pic1

I have trieddf_cause_death_france.select(regexp_replace(col("Value")," ","")) It does works but it removes all other columns from my spark dataframe.

pic2



Solution 1:[1]

please ignore this question. I am able to solve it.

In case you want to know my solution, here it is.

df_cause_death_france.withColumn('VALUE', regexp_replace('Value', ' ','')).show()

output = https://i.stack.imgur.com/1bljf.png

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Aaditya Rathi