【发布时间】:2017-12-08 22:13:47
【问题描述】:
我不想读取文本文件,我想对现有数据框执行操作
我的DataFrame只有一列文本,就像一个文件,"tabSeparator"。
这是一个结构化文件,有3列,分隔符是一个标签。
如果 列 有一个嵌入的 tab,它会用双引号括起来 ("xxx xx")
例子:
-------------------------
col_0
-------------------------
c11 c12 c13
c21 c22 c23
"c 31" "c 32" c33
我正在使用这个正则表达式: 我正在使用 pyspark 和 Jupyter Notebook
myre = '([\\t ]?(\\".*?\\"|[^\\t ]+))'
df = textDF.withColumn("tmp", split( col("_c0"), myre))\
.select(\
col("tmp").getItem(0).alias("col_1"),\
col("tmp").getItem(1).alias("col_2"),\
col("tmp").getItem(2).alias("col_3")
)
不确定问题出在正则表达式还是我解析文件的方式上,但我无法创建一个解析了 3 列的新 DataFrame,resulting on:
-------------------
|col_1|col_2|col_3|
------+-----+------
| c11 | c12 | c13 |
| c21 | c22 | c23 |
| c 31| c 32| c 33|
-------------------
【问题讨论】:
标签: python regex pyspark spark-dataframe