相关疑难解决方法(0)

将正则表达式应用于pandas数据帧

我在python数据帧中应用正则表达式函数列时遇到问题.这是我的数据帧的负责人:

               Name   Season          School   G    MP  FGA  3P  3PA    3P%
 74       Joe Dumars  1982-83   McNeese State  29   NaN  487   5    8  0.625   
 84      Sam Vincent  1982-83  Michigan State  30  1066  401   5   11  0.455   
 176  Gerald Wilkins  1982-83     Chattanooga  30   820  350   0    2  0.000   
 177  Gerald Wilkins  1983-84     Chattanooga  23   737  297   3   10  0.300   
 243    Delaney Rudd  1982-83     Wake Forest  32  1004  324  13   29  0.448  
Run Code Online (Sandbox Code Playgroud)

我认为我已经很好地掌握了将函数应用于Dataframes,所以也许我的正则表达式技能缺乏.

这是我放在一起的东西:

import re

def split_it(year):
    return re.findall('(\d\d\d\d)', year)

 df['Season2'] = df['Season'].apply(split_it(x)) …
Run Code Online (Sandbox Code Playgroud)

python regex pandas

18
推荐指数
3
解决办法
3万
查看次数

标签 统计

pandas ×1

python ×1

regex ×1