I am reading csv file into spark dataframe. The csv has empty spaces " " in many columns, i want to remove these empty spaces. There are 500 columns in csv, So i cannot specific columns manually in my code
Sample data:
ADVANCE_TYPE CHNG_DT BU_IN
A 20190718 1
20190728 2
20190714
B 20190705
20190724 4
Code:
from pyspark.sql.functions import col,when,regexp_replace,trim
df_csv = spark.read.options(header='true').options(delimiter=',').options(inferSchema='true').options(nullValue="None").csv("test41.csv")
for col_name in df_csv.columns:
df_csv = df_csv.select(trim(col(col_name)))
But these code is not removing empty spaces. Please help!