text_html_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

sales = pd.read_csv('../input/competitive-data-science-predict-future-sales/sales_train.csv')
test_data = pd.read_csv('../input/competitive-data-science-predict-future-sales/test.csv')
items = pd.read_csv('../input/competitive-data-science-predict-future-sales/items.csv')
item_category = pd.read_csv('../input/competitive-data-science-predict-future-sales/item_categories.csv')
shops = pd.read_csv('../input/competitive-data-science-predict-future-sales/shops.csv')

def lag_feature(all_data, list_lags, index_cols, cols_to_rename):
    shift_range = list_lags
    for month_shift in tqdm_notebook(shift_range):
        train_shift = all_data[index_cols + cols_to_rename].copy()
        train_shift['date_block_num'] = train_shift['date_block_num'] + month_shift
        foo = lambda x: '{}_lag_{}'.format(x, month_shift) if x in cols_to_rename else x
        train_shift = train_shift.rename(columns=foo)
        all_data = pd.merge(all_data, train_shift, on=index_cols, how='left').fillna(0)
    del train_shift
    return all_data

Monthly_sales = sales.groupby(["date_block_num", "shop_id"])['item_cnt_day'].sum().reset_index(name = 'item_cnt_month')

fig, axs = plt.subplots(10, 6)

for i in range(60):
  shop_sale_per_month = Monthly_sales.loc[Monthly_sales['shop_id']==i]
  axs[i//6,i%6].tick_params(axis='both', which='both', bottom=False, top= False, labelbottom=False, right=False, left=False, labelleft=False)
  axs[i//6,i%6].plot(shop_sale_per_month['date_block_num'], shop_sale_per_month['item_cnt_month'])

del Monthly_sales, shop_sale_per_month

sales.loc[sales.shop_id == 0, 'shop_id'] = 57
test_data.loc[test_data.shop_id == 0, 'shop_id'] = 57
sales.loc[sales.shop_id == 1, 'shop_id'] = 58
test_data.loc[test_data.shop_id == 1, 'shop_id'] = 58
sales.loc[sales.shop_id == 10, 'shop_id'] = 11
test_data.loc[test_data.shop_id == 10, 'shop_id'] = 11
sales = sales[sales.item_cnt_day < 1001]

temp_df = pd.merge(test_data[['shop_id', 'item_id']], sales[['shop_id', 'item_id']], on=['shop_id', 'item_id'], how='left', indicator='Exist')
temp_var = (temp_df['Exist'] == 'left_only').sum()
print('Number of unique shop-item combination in the test set that do not exist in the training set:', temp_var)