In [1]:
# import libaries
import numpy as np
import pandas as pd
import matplotlib.pyplot as pyplt
from IPython.display import Image
import seaborn as sns
In [2]:
# Plot in ipython notebook
%matplotlib inline
In [3]:
# Set Display Options
pd.options.display.max_rows = 15
In [4]:
stores = pd.read_csv('kaggle_walmart_data/stores.csv')
sales = pd.read_csv('kaggle_walmart_data/train.csv')
features = pd.read_csv('kaggle_walmart_data/features.csv')
In [5]:
print('Rows of Weekly Sales: ', len(sales))
In [6]:
sales.dtypes
Out[6]:
In [7]:
sales.head()
Out[7]:
In [8]:
sales.Date = pd.to_datetime(sales.Date)
In [9]:
sales.dtypes
Out[9]:
In [10]:
def topn(group, field, n=5):
return group.sort_index(by=field, ascending=False)[:n]
sales.groupby('Store').apply(topn, 'Weekly_Sales', 3)
Out[10]:
In [14]:
sales_monthly_store1 = sales[sales.Store == 1].set_index('Date').sort_index().resample('M', how='sum')
In [16]:
sales_monthly.Weekly_Sales.plot()
Out[16]:
In [ ]: