text_plain_output_1.png
import numpy as np # linear algebra

import pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)

import numpy as np
import pandas as pd
train_data = pd.read_csv('../input/train.csv', usecols=['Producto_ID', 'Demanda_uni_equil'])

train_data['log_Dem'] = np.log(np.array(train_data['Demanda_uni_equil'].tolist()) + 1)

mean_data = train_data.groupby(train_data['Producto_ID']).mean()

test_data = pd.read_csv('../input/test.csv', usecols=['id', 'Producto_ID'])
target = np.zeros(test_data.shape[0])
log_target = np.zeros(test_data.shape[0])
for pid in mean_data.index:
    target[test_data[test_data['Producto_ID'] == pid]['id'].values] = mean_data.ix[pid]['Demanda_uni_equil']
    log_target[test_data[test_data['Producto_ID'] == pid]['id'].values] = mean_data.ix[pid]['log_Dem']

test_data['Demanda_uni_equil'] = np.exp(log_target) - 1
test_data.to_csv('result_groupmean_log.csv', index=False, columns=['id', 'Demanda_uni_equil'])

test_data.shape