I have the following data frame:
AIRCRAFT
B738 (C-GKWJ)
A321 (C-FJNX)
and using this code to extract only TYPE,
def extract_type(aircraft):
return aircraft.split(" ")[0]
data['TYPE'] = data['AIRCRAFT'].apply(lambda x: extract_type(x))
my expectation is:
AIRCRAFT TYPE
B738 (C-GKWJ) B738
A321 (C-FJNX) A321
but im getting:
AIRCRAFT TYPE
B738 (C-GKWJ) B738 (C-GKWJ)
A321 (C-FJNX) A321 (C-FJNX)
when testing extract_type function, it works fine
def extract_type(aircraft):
return aircraft.split(" ")[0]
extract_type("B737 (C-GWJT)")
returns 'B737'
Why it doesn't work with data frame and lambda function? Thanks