text_plain_output_1.png
import pandas as pd

train = pd.read_csv('../input/sales_train.csv')

test = pd.read_csv('../input/test.csv')

items_cats = pd.read_csv('../input/item_categories.csv')

items = pd.read_csv('../input/items.csv')

shops = pd.read_csv('../input/shops.csv')

train.columns.values

shops_train = train.groupby(['shop_id']).groups.keys()
len(shops_train)

item_train = train.groupby(['item_id']).groups.keys()
len(item_train)

shops_test = test.groupby(['shop_id']).groups.keys()
len(shops_test)

items_test = test.groupby(['item_id']).groups.keys()
len(items_test)

train_df = train.groupby(['shop_id', 'item_id', 'date_block_num']).sum().reset_index().sort_values(by=['item_id', 'shop_id'])

train_df['m1'] = train_df.groupby(['shop_id', 'item_id']).item_cnt_day.shift()
train_df['m1'].fillna(0, inplace=True)
train_df

train_df['m2'] = train_df.groupby(['shop_id', 'item_id']).m1.shift()
train_df['m2'].fillna(0, inplace=True)
train_df.head()