I'm having trouble applying a regex function a column in a python dataframe. Here is the head of my dataframe:
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
I thought I had a pretty good grasp of applying functions to Dataframes, so maybe my Regex skills are lacking.
Here is what I put together:
import re
def split_it(year):
return re.findall('(\d\d\d\d)', year)
df['Season2'] = df['Season'].apply(split_it(x))
TypeError: expected string or buffer
Output would be a column called Season2 that contains the year before the hyphen. I'm sure theres an easier way to do it without regex, but more importantly, i'm trying to figure out what I did wrong
Thanks for any help in advance.