如何在pyspark中拆分包含正斜杠的列表

How to split a list which contains forwardslash in pyspark

你好,我有一份清单如下

    [(datetime.datetime(2020,8,20,19,40,27,tzinfo=tzlocal()), 'AAA/v1/b1/c1/text.txt'), 
    (datetime.datetime(2020,8,20,14,48,28,tzinfo=tzlocal()), 'BBB/v2/b2/c2/text1.txt')]

我该如何分割,所以输出如下所示

       Timestamp                V     B     C       T
       2020/8/20 19:40:27       v1    b1    c1      text.txt
       2020/8/20 14:48:28       v2    b2    c2      text1.txt

映射您的列表以拆分元素并创建数据框。

ll = [(11, 'AAA/v1/b1/c1/text.txt'), (22, 'BBB/v2/b2/c2/text1.txt')]
ll = list(map(lambda x: (x[0], *x[1].split('/')[1:]), ll))
cc= ['Timestamp', 'V', 'B', 'C', 'T']

df = spark.createDataFrame(ll, cc)
df.show(10, False)

+---------+---+---+---+---------+
|Timestamp|V  |B  |C  |T        |
+---------+---+---+---+---------+
|11       |v1 |b1 |c1 |text.txt |
|22       |v2 |b2 |c2 |text1.txt|
+---------+---+---+---+---------+