import pandas as pd
import numpy as np
from sklearn import preprocessing

df = pd.read_csv('Adult.csv')

print(df.head())

lb = preprocessing.LabelBinarizer()
encodedvalues = lb.fit_transform(df.iloc[:,8:9])
print('Race')
print(encodedvalues)

dfOneHot = pd.DataFrame(encodedvalues, columns = ["A"+str(int(i)) for i in range(encodedvalues.shape[1])])
df = pd.concat([df, dfOneHot], axis=1)

encodedvalues = lb.fit_transform(df.iloc[:,9:10])
print('Gender')
print(encodedvalues)

dfOneHot = pd.DataFrame(encodedvalues, columns = ["B"+str(int(i)) for i in range(encodedvalues.shape[1])])
df = pd.concat([df, dfOneHot], axis=1)

encodedvalues = lb.fit_transform(df.iloc[:,13:14])
print('Country')
print(encodedvalues)

dfOneHot = pd.DataFrame(encodedvalues, columns = ["C"+str(int(i)) for i in range(encodedvalues.shape[1])])
df = pd.concat([df, dfOneHot], axis=1)

# delete the categorical column just replaced
df.drop(df.columns[13], axis=1)
df.drop(df.columns[8], axis=1)
df.drop(df.columns[9], axis=1)

print(df.head())
