I'm trying to map some non numerical values in a pandas dataset that contains information from passengers that were on the Titanic. Right now I'm trying to map the ports where passengers embarked from. There are 3 ports and I'm trying to map them by adding a column for each port. 0 if they embarked from that port 1 if not.
I tried doing something similar with sex. I added another column with a 0 if the sex was male and 1 if the sex was female. That worked, but when I try doing this with the ports I get a "'float' object is not subscriptable" error.
import pandas as pd
#opening the data
train_path = #path to data set
passengers = pd.read_csv(train_path)
#creating a copy
passengers_copy = passengers
#mapping sex
passengers_copy['SexBin'] = [0 if x[0] == 'm' else 1 for x in passengers_copy['Sex']]
#trying to map the first port
passengers_copy['EmbarkedS'] = [0 if x[0] == 'S' else 1 for x in passengers_copy['Embarked']]