Skip to content

Instantly share code, notes, and snippets.

@Akramz
Created December 14, 2015 21:43
Show Gist options
  • Save Akramz/0a3fd9ea14262fd3a598 to your computer and use it in GitHub Desktop.
Save Akramz/0a3fd9ea14262fd3a598 to your computer and use it in GitHub Desktop.
import pandas as pd
from sys import exit
import numpy as np
data = pd.read_csv('../../train.csv')
data = data[['Survived', 'Pclass', 'Sex', 'SibSp', 'Parch', 'Embarked']].dropna()
# male = 0
# female = 1
# S = 0
# C = 1
# Q = 2
for index, row in data.iterrows():
if data.loc[index, "Sex"] == 'male':
data.loc[index, "Sex"] = 0
if data.loc[index, "Sex"] == 'female':
data.loc[index, "Sex"] = 1
if data.loc[index, "Embarked"] == 'S':
data.loc[index, "Embarked"] = 0
if data.loc[index, "Embarked"] == 'C':
data.loc[index, "Embarked"] = 1
if data.loc[index, "Embarked"] == 'Q':
data.loc[index, "Embarked"] = 2
data.to_csv('../train1.csv', sep=',')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment