https://machinelearningmastery.com/convert-time-series-supervised-learning-problem-python/
%matplotlib inline
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import warnings
import seaborn as sns
import scipy.stats as st
import os
import re
warnings.filterwarnings('ignore')
pd.set_option('display.max_rows', None)
pd.set_option('display.max_columns', None)
pd.set_option('display.max_colwidth', 100)
train = pd.read_csv('demand_train_A.csv', sep=',', index_col=0)
test = pd.read_csv('demand_test_A.csv', sep=',', index_col=0)
inventory_info = pd.read_csv('inventory_info_A.csv', sep=',', index_col=0)
geo_topo = pd.read_csv('geo_topo.csv', sep=',')
product_topo = pd.read_csv('product_topo.csv', sep=',')
weight = pd.read_csv('weight_A.csv', sep=',', index_col=0)
geo = pd.melt(geo_topo, value_vars=list(geo_topo.columns),
var_name='unit', value_name='geography_level')
geo.head(10)
product = product_topo.reset_index().set_index('index')
product = product_topo.stack()
product.index = product.index.rename('unit', level=1)
product.name = 'product_level'
product = product.reset_index()
del product['level_0']
product.head(10)
all_data = pd.concat([train, test])
inventory_info['init_qty'] = inventory_info['qty']
del inventory_info['qty']
all_data.columns, inventory_info.columns
all_data.shape
data = pd.merge(inventory_info, all_data, on=['unit','geography_level', 'geography', 'product_level','product'])
data.head()
data.rename(columns={'ts_x':'init_ts', 'ts_y':'ts'})