【发布时间】:2019-05-01 15:25:09
【问题描述】:
我必须提取以“Year”开头并以“\n”结尾的字符串,但对于 Pandas 数据框中单元格中出现的每一行。 另外,我想在单元格末尾删除 \n。
这是数据框:
df
Column1
not_important1\nnot_important2\nE012-855 Year-1972\nE012-856 Year-1983\nnot_important3\nE012-857 Year-1977\nnot_important4\nnot_important5\nE012-858 Year-2012\n
not_important6\nnot_important7\nE013-200 Year-1982\nE013-201 Year-1984\nnot_important8\nE013-202 Year-1987\n
not_important9\nnot_important10\nE014-652 Year-1988\nE014-653 Year-1980\nnot_important11\nE014-654 Year-1989\n
这就是我想要的:
df
Column1
Year-1972\nYear-1983\nYear-1977\nYear-2012
Year-1982\nYear-1984\nYear-1987
Year-1988\nYear-1980\nYear-1989
如何做到这一点?
【问题讨论】:
标签: python regex string pandas extract