text_html_output_1.png
from sklearn.preprocessing import LabelEncoder

import pandas as pd

gatrain = pd.read_csv('../input/gender_age_train.csv')
gatest = pd.read_csv('../input/gender_age_test.csv')

letarget = LabelEncoder().fit(gatrain.group.values)
y = letarget.transform(gatrain.group.values)
n_classes = len(letarget.classes_)

phone = pd.read_csv('../input/phone_brand_device_model.csv', encoding='utf-8')

phone = phone.drop_duplicates('device_id', keep='first')

lebrand = LabelEncoder().fit(phone.phone_brand)
phone['brand'] = lebrand.transform(phone.phone_brand)
m = phone.phone_brand.str.cat(phone.device_model)
lemodel = LabelEncoder().fit(m)
phone['model'] = lemodel.transform(m)

train = gatrain.merge(phone[['device_id', 'brand', 'model']], how='left', on='device_id')

ptrain = gatrain.merge(phone[['device_id', 'brand', 'model']], how='left', on='device_id')
ptrain.head(3)