# This Python 3 environment comes with many helpful analytics libraries installed
# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python
# For example, here's several helpful packages to load

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

# Input data files are available in the read-only "../input/" directory
# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory

import os
for dirname, _, filenames in os.walk('/kaggle/input'):
    for filename in filenames:
        print(os.path.join(dirname, filename))

# You can write up to 20GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using "Save & Run All" 
# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session
import matplotlib.pyplot as plt
import seaborn as sns
df_stores = pd.read_csv('/kaggle/input/retaildataset/stores data-set.csv')
df_stores.head()
df_features = pd.read_csv('/kaggle/input/retaildataset/Features data set.csv')
df_features.head()
df_sales = pd.read_csv('/kaggle/input/retaildataset/sales data-set.csv')
df_sales.head()
df_stores_features = df_stores.merge(right = df_features, on = 'Store')

df_merge = df_stores_features.merge(right = df_sales, on = ['Store', 'Date', 'IsHoliday'])
df_merge.sample(10)
df_merge.info()
df_merge.describe()
"""
#### Converting date column into datetime
"""
df_merge['Date'] = pd.to_datetime(df_merge['Date'])
df_temp = df_merge.copy(deep=True)
df_temp['MarkDown'] = df_temp['MarkDown1'] + df_temp['MarkDown2'] +df_temp['MarkDown3'] +df_temp['MarkDown4'] + df_temp['MarkDown5']
df_temp.drop(['MarkDown1', 'MarkDown2', 'MarkDown3', 'MarkDown4', 'MarkDown5'], inplace = True, axis = 1)
fig, ax = plt.subplots(figsize=(20,12))
sns.heatmap(df_temp.corr(),annot=True)
# df_temp.head
df_merge[['Date', 'Temperature', 'Fuel_Price', 'CPI', 'Unemployment', 
    'MarkDown1', 'MarkDown2', 'MarkDown3', 'MarkDown4', 'MarkDown5']].plot(x='Date', subplots=True, figsize=(20,15))
plt.show()
"""
### Cumulative Weekly Sales Plot
"""
df_temp = df_merge.groupby('Date').sum()['Weekly_Sales'].reset_index()
fig, ax = plt.subplots(figsize=(20,12))
ax.plot('Date', 'Weekly_Sales', data=df_temp)
df_merge.Date.apply(lambda x: x.month)
df_temp = df_merge.groupby(df_merge.Date.apply(lambda x: x.month)).sum()['Weekly_Sales'].reset_index()
plt.figure(figsize=(10, 5))
sns.barplot(x=df_temp.Date,y=df_temp.Weekly_Sales)
plt.title("Month wise Sales")
plt.xlabel("Month")
plt.ylabel("Sales")
"""
### Performance Based on Stores
"""
df_temp = df_merge.groupby('Type').sum()['Weekly_Sales'].reset_index()
fig, ax = plt.subplots(figsize=(20,12))
ax.bar('Type', 'Weekly_Sales', data=df_temp)