def rename_brands(phone_models):
""" recast all phone brands and model as string integers brand_i and model_j """
brands_table = {}
i = 0
for brand in pd.unique(phone_models['phone_brand']):
brands_table[brand] = 'brand_%s' %i
i += 1
models_table = {}
i = 0
for model in pd.unique(phone_models['device_model']):
models_table[model] = 'model_%s' %i
i += 1
converted = []
for item in zip(phone_models['phone_brand'],phone_models['device_model']):
converted.append((brands_table[item[0]],models_table[item[1]]))
phone_models['phone_brand'] = [x[0] for x in converted]
phone_models['device_model'] = [x[1] for x in converted]
return phone_models
评论列表
文章目录