Created
January 10, 2016 05:34
-
-
Save staticor/ee9730d8ef0b01222428 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
df_train = pd.read_csv('../data/titanic/train.csv') | |
def clean_data(df): | |
# Get the unique values of Sex | |
sexes = np.sort(df['Sex'].unique()) | |
# Generate a mapping of Sex from a string to a number representation | |
genders_mapping = dict(zip(sexes, range(0, len(sexes) + 1))) | |
# Transform Sex from a string to a number representation | |
df['Sex_Val'] = df['Sex'].map(genders_mapping).astype(int) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment