Feb 7, 2023
Handling Column name with space in Apache Spark
To handle column names with spaces in Apache Spark, you can use backticks (`) to escape the column name. For example:
df.select(col("`Column Name with Space`")).show()
Alternatively, you can rename the column to a name without spaces using withColumnRenamed
method:
df.withColumnRenamed("Column Name with Space", "ColumnNameWithoutSpace")
.select(col("ColumnNameWithoutSpace")).show()