【发布时间】:2019-07-17 21:59:40
【问题描述】:
我想从我的数据框列 data3['CopyRight'] 中提取年份。
CopyRight
2015 Sony Music Entertainment
2015 Ultra Records , LLC under exclusive license
2014 , 2015 Epic Records , a division of Sony Music Entertainment
Compilation ( P ) 2014 Epic Records , a division of Sony Music Entertainment
2014 , 2015 Epic Records , a division of Sony Music Entertainment
2014 , 2015 Epic Records , a division of Sony Music Entertainment
我正在使用下面的代码来提取年份:
data3['CopyRight_year'] = data3['CopyRight'].str.extract('([0-9]+)', expand=False).str.strip()
使用我的代码,我只能得到第一次出现的年份。
CopyRight_year
2015
2015
2014
2014
2014
2014
我想提取列中提到的所有年份。
预期输出
CopyRight_year
2015
2015
2014,2015
2014
2014,2015
2014,2015
【问题讨论】:
标签: python regex pandas dataframe