[英]Regex to find date format
I have a dataframe with column Date
.我有一个 dataframe 列
Date
。 It contains values like 2022-01-03
.它包含类似
2022-01-03
的值。
I want to create a new df with only those rows that fulfil the conditions:我想创建一个只有满足条件的行的新 df:
20
20
开始-
signs between the four-digit year and the two-digit month and then between the two-digit month and two-digit day -
在四位数年份和两位数月份之间签名,然后在两位数月份和两位数日期之间签名The below doesn't work:以下不起作用:
df2 = my_df.where('Date like "20\d\d-\d\d-\d\d"')
Any ideas?有任何想法吗?
You may use rlike()
here:你可以在这里使用
rlike()
:
df2 = my_df.filter(col("Date").rlike("20[0-9]{2}-[0-9]{2}-[0-9]{2}"))
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.