2024-04-26 07:58:43 发布
网友
我正在为推荐系统使用电影镜头数据集。我想把电影的年份从标题栏中分出来,放在一个叫做“年份”的新功能中。你知道吗
import re title = df3.title df3.Year = re.findall('[(...)]', title)
标题 危险思想(1995) 轨枕(1996) 天堂电影院(Nuovo Cinema Paradiso)(1989)
假设它总是在字符串的末尾:
rgx = re.compile(r"(?:\((\d{4})\))?\s*$") match = rgx.search(txt) # group 1 will be None if not matched else eg '1989' year = match.group(1)
expr = re.compile('\((....)\)') df3.Year = re.findall(expr, title)[-1]
假设它总是在字符串的末尾:
相关问题 更多 >
编程相关推荐