application_vnd.jupyter.stderr_output_1.png
from sklearn.preprocessing import LabelEncoder

import pandas as pd

import pandas as pd

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

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

dup = phone.groupby('device_id').size()
dup = dup[dup > 1]
dup.shape

dup = phone.loc[phone.device_id.isin(dup.index)]
first = dup.groupby('device_id').first()
last = dup.groupby('device_id').last()

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)
phone['old_model'] = LabelEncoder().fit_transform(phone.device_model)

train = gatrain.merge(phone)

train['y'] = LabelEncoder().fit_transform(train['group'])
train.head()