text_plain_output_1.png image_output_1.png
import matplotlib.pyplot as plt

import pandas as pd

import seaborn as sns

df_train = pd.read_csv('../input/train.csv')
df_store = pd.read_csv('../input/store.csv')
df_test = pd.read_csv('../input/test.csv')

fig, (axis1) = plt.subplots(1,1,figsize=(15,4))
sns.countplot(x = 'Open', hue = 'DayOfWeek', data = df_train,)

df_train['Year'] = df_train['Date'].apply(lambda x: int(x[:4]))

df_train['Month'] = df_train['Date'].apply(lambda x: int(x[5:7]))

average_monthly_sales = df_train.groupby('Month')["Sales"].mean()
fig = plt.subplots(1,1,sharex=True,figsize=(10,5))
average_monthly_sales.plot(legend=True,marker='o',title="Average Sales")

average_daily_sales = df_train.groupby('Date')["Sales"].mean()
fig = plt.subplots(1,1,sharex=True,figsize=(25,8))
average_daily_sales.plot(title="Average Daily Sales")

average_daily_visits = df_train.groupby('Date')["Customers"].mean()
fig = plt.subplots(1,1,sharex=True,figsize=(25,8))
average_daily_visits.plot(title="Average Daily Visits")

fig, (axis1,axis2) = plt.subplots(2,1,sharex=True,figsize=(15,8))

average_monthly_sales = df_train.groupby('Month')["Sales"].mean()

# plot average sales over time (year-month)
ax1 = average_monthly_sales.plot(legend = False, ax = axis1, marker = 'o', 
                                title = "Avg. Monthly Sales")

ax1.set_xticks(range(len(average_monthly_sales)))
ax1.set_xticklabels(average_monthly_sales.index.tolist(), rotation=90)

average_monthly_sales_change = df_train.groupby('Month')["Sales"].sum().pct_change()
# plot precent change for sales over time(year-month)
ax2 = average_monthly_sales_change.plot(legend = False, ax = axis2, marker = 'o', 
                                        colormap = "summer", title = "% Change Monthly Sales")

df_train.StateHoliday.unique()

df_train['StateHoliday'] = df_train['StateHoliday'].replace(0, '0')
df_train.StateHoliday.unique()