我有一个看起来像这样的数据框:
Film Description
0 Batman Viewed in 2021-10-04T14:30:31Z City Hall, London
1 Superman Aired 2012-01-04R11:01:10Z in the USA first
2 Hulk 2010-07-04S07:22:02Z Still being produced
我想从“说明”列的每一行中删除日期时间,如下所示:
Film Description
0 Batman Viewed in City Hall, London
1 Superman Aired in the USA first
2 Hulk Still being produced
我已经尝试过此字符串正则表达式:
df['Description'] = df['Description '].str.replace(r'\^(\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2})Z', '')
\^
匹配插入符号。
除此之外T
,我看R
和S
在日期时间的邮票,他们必须加入。
使用
\s*\b\d{4}-\d{2}-\d{2}[TRS]\d{2}:\d{2}:\d{2}Z\b
见证明。
解释
--------------------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0 or
more times (matching the most amount
possible))
--------------------------------------------------------------------------------
\b the boundary between a word char (\w) and
something that is not a word char
--------------------------------------------------------------------------------
\d{4} digits (0-9) (4 times)
--------------------------------------------------------------------------------
- '-'
--------------------------------------------------------------------------------
\d{2} digits (0-9) (2 times)
--------------------------------------------------------------------------------
- '-'
--------------------------------------------------------------------------------
\d{2} digits (0-9) (2 times)
--------------------------------------------------------------------------------
[TRS] any character of: 'T', 'R', 'S'
--------------------------------------------------------------------------------
\d{2} digits (0-9) (2 times)
--------------------------------------------------------------------------------
: ':'
--------------------------------------------------------------------------------
\d{2} digits (0-9) (2 times)
--------------------------------------------------------------------------------
: ':'
--------------------------------------------------------------------------------
\d{2} digits (0-9) (2 times)
--------------------------------------------------------------------------------
Z 'Z'
--------------------------------------------------------------------------------
\b the boundary between a word char (\w) and
something that is not a word char
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句