text_html_output_1.png
import matplotlib.pyplot as plt

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

train_df = pd.read_csv('../input/store-sales-time-series-forecasting/train.csv', index_col='id')
test_df = pd.read_csv('../input/store-sales-time-series-forecasting/test.csv', index_col='id')

train_df.date = pd.to_datetime(train_df.date)
test_df.date = pd.to_datetime(test_df.date)
train_df['year'] = train_df.date.dt.year
test_df['year'] = test_df.date.dt.year
train_df['month'] = train_df.date.dt.month
test_df['month'] = test_df.date.dt.month
train_df['dayofmonth'] = train_df.date.dt.day
test_df['dayofmonth'] = test_df.date.dt.day
train_df['dayofweek'] = train_df.date.dt.dayofweek
test_df['dayofweek'] = test_df.date.dt.dayofweek
train_df['dayname'] = train_df.date.dt.strftime('%A')
test_df['dayname'] = test_df.date.dt.strftime('%A')

train_df.family.unique()

fig= plt.figure(figsize=(10,120))
fig.subplots_adjust(hspace=0.75)
for i,product in enumerate(train_df.family.unique()):
    ax = fig.add_subplot(33,1,i+1)
    select = train_df.query('family==@product')
    for year in [2013,2014,2015,2016,2017]: 
        select.query('year==@year').groupby('month').sales.mean().plot(ax=ax,label=year)
    plt.title(product)
    ax.legend();

train_df.groupby('dayofmonth').sales.mean().plot(kind='bar')
plt.title('Sales Average by Day of Month')