我正在尝试读取文本文件,其内容如下:
a [b c] "d e" f
除了解析[b c]
之外,此代码可以正常工作,它将b
和c
拆分为单独的列。有没有办法忽略它们之间的空白?
display( spark.read.load(file_path, format="csv",sep = ' ', header="false"))
答案 0 :(得分:1)
让它分裂...我认为这没问题。你可以试试这个
import org.apache.spark.sql.functions.lit
df
.withColumn("timestamp", concat($"col1", lit(" "),$"col2"))
.withColumn("timestamp", $"timestamp".cast("date"))
其中col1 = 2014年9月24日:22:25:44&col2 = +0000