I am trying to use lambda and regex to extract text from a string in pandas dataframe, I have regex right and can fill a new column with the right data, but it is surrounded by [ ]?
Code to build dataframe:
carTypes = {'Car Class Description' : ['A - ECAR - Economy',
'C - ICAR - Intermediate',
'D - DCAR - Full Size',
'E - FFAR - Large SUV - 5 Seater',
'E1 - GFAR - Large SUV - 7 Seater']}
df_carTypes = pd.DataFrame(carTypes)
Code to apply regex to each row in dataframe and generate and populate a new column with result:
df_carTypes['Car Class Code'] = df_carTypes['Car Class Description'].apply(lambda x: re.findall(r'^\w{1,2}',x))
Result:
I get a new column as required with the right result, but [ ] surrounding the output, e.g. [A]
Can someone assist?
Sorry I can't format better...