次のようなデータフレームがあります。
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]
コメントを追加