我想从sparkDataframe列中的字符串中提取数字字符。
例如
id val (string)
58 [dttg] 201805_mogtca_onvt
91 20050221_frcas
17 201709 dcsevas
我需要:
id a_date year month
58 201805 2018 05
91 20050221 2005 02
17 201709 2017 09
我正在尝试:
df.withColumn('date', DF.to_date(F.col('val').isdigit() # how to get digital chars ?
1条答案
按热度按时间vsdwdz231#
您应该首先通过regex\u replace删除所有非数字字符,例如:
然后,由于每行中的时间格式似乎不同,所以最简单的方法是使用子字符串
输入
输出