I have a column structured like this: album: "The Dark Side Of The Moon" (1973)
there is the name of the album and at the end, between parenthesis, the year.
我只需要从该列中删除最后一部分,并创建一个仅包含年份的名为“ year”的新列。
I 'm not sure if use re.search()
, but I've tried this:
data['year'] = data['Album'].str.extract(r'\(\d*\)')
如果我在单个字符串上使用re.search()测试此模式,则该模式有效,并且在用于正则表达式的在线工具中也可以使用。
那我该怎么办?
谢谢!
您仍然可以使用您的re.search