小编Adi*_*rma的帖子

在python中使用Regex提取日期

我想从我的数据框列中提取年份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
Run Code Online (Sandbox Code Playgroud)

我使用以下代码来提取年份:

data3['CopyRight_year'] = data3['CopyRight'].str.extract('([0-9]+)', expand=False).str.strip()
Run Code Online (Sandbox Code Playgroud)

我的代码我只获得了第一次出现的年份.

CopyRight_year
2015
2015
2014
2014
2014
2014
Run Code Online (Sandbox Code Playgroud)

我想提取专栏中提到的所有年份. …

python regex dataframe pandas

5
推荐指数
1
解决办法
80
查看次数

标签 统计

dataframe ×1

pandas ×1

python ×1

regex ×1