February 2018
Intermediate to advanced
450 pages
11h 27m
English
This approach is used to create a numerical categorical feature from any other feature. In pandas, the factorize() function does that. This type of transformation is useful if your feature is an alphanumeric categorical variable. In the Titanic data samples, we can transform the Cabin feature into a categorical feature, representing the letter of the cabin:
# the cabin number is a sequence of of alphanumerical digits, so we are going to create some features# from the alphabetical part of itdf_titanic_data['CabinLetter'] = df_titanic_data['Cabin'].map(lambda l: get_cabin_letter(l))df_titanic_data['CabinLetter'] = pd.factorize(df_titanic_data['CabinLetter'])[0]
def get_cabin_letter(cabin_value): # searching for the letters in the ...
Read now
Unlock full access