{"cells":[{"metadata":{"_cell_guid":"9910308a-051b-4680-a793-26cd4b53d678","_uuid":"d51fbf4d9ec4e9759471105a636f58cef0149d45","trusted":false},"cell_type":"code","source":"# Importing the relevant libraries\nimport IPython.display\nimport pandas as pd\nimport seaborn as sns\nimport plotly.offline as py\npy.init_notebook_mode(connected=True)\nimport plotly.graph_objs as go\nfrom matplotlib import pyplot as plt","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"62a7f5f4-7e97-4f25-b3b1-2d2eb877a28e","_uuid":"e64a4746b9f17aa07b09ce1b5c2bbe877277ec69","trusted":false},"cell_type":"code","source":"items = pd.read_csv(\"../input/items.csv\")\nholiday_events = pd.read_csv(\"../input/holidays_events.csv\")\nstores = pd.read_csv(\"../input/stores.csv\")\noil = pd.read_csv(\"../input/oil.csv\")\ntransactions = pd.read_csv(\"../input/transactions.csv\",parse_dates=['date'])\ntrain = pd.read_csv(\"../input/train.csv\", parse_dates=['date'])","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"ab77f658-fa78-4457-8c0f-f4d1fab86b9a","_uuid":"0a4a85727cf77c4e5b999284dc92b79c29542f4e","trusted":false},"cell_type":"code","source":"print(train.shape)\ntrain.head()","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"c65068ee-6c56-45c5-bc77-9540566aeaec","_uuid":"b44de04acae83e693d7d1a722040e48023280788","trusted":false},"cell_type":"code","source":"# Check for NULL values in all files\nprint(\"Nulls in train: {0} => {1}\".format(train.columns.values, train.isnull().any().values))\nprint('---')\nprint(\"Nulls in oil: {0} => {1}\".format(oil.columns.values,oil.isnull().any().values))\nprint('---')\nprint(\"Nulls in holiday_events: {0} => {1}\".format(holiday_events.columns.values,holiday_events.isnull().any().values))\nprint('---')\nprint(\"Nulls in stores: {0} => {1}\".format(stores.columns.values,stores.isnull().any().values))\nprint('---')\nprint(\"Nulls in transactions: {0} => {1}\".format(transactions.columns.values,transactions.isnull().any().values))","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"90851902-7917-4600-bf9c-bf963a21b141","_uuid":"fc063ffd06e810a63adda8c3de5097a957f50db9","trusted":false},"cell_type":"code","source":"# EDA for oil.csv begins here #\noil.head(3)","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"336afd48-8532-441b-932c-6add917898b0","_uuid":"7ac984f10728dabb353b78f2da01eb81438f12af","trusted":false},"cell_type":"code","source":"# Plotting graph for oil price trends\ntrace = go.Scatter(\n    name='Oil prices',\n    x=oil['date'],\n    y=oil['dcoilwtico'].dropna(),\n    mode='lines',\n   )\n\ndata = [trace]\n\nlayout = go.Layout(\n    yaxis = dict(title = 'Daily Oil price'),\n    showlegend = True)\nfig = go.Figure(data = data, layout = layout)\npy.iplot(fig, filename='pandas-time-series-error-bars')","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"b5ed6b45-f4e5-4add-bd6a-5de7625fc55a","_uuid":"27cd069a0b914d08f33eb5f766c6a8c3a6fa380e","trusted":false},"cell_type":"code","source":"# EDA for holiday_events.csv begins here #\nholiday_events.head(3)","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"923f6465-8fcb-42e7-960e-ecacb4b78b4a","_uuid":"2db66220fd854c439e724bffcef35a2a3ca8ad4d","trusted":false},"cell_type":"code","source":"holiday_events.type.unique()","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"642d07c6-3cf3-43b8-8731-393d83d6c9c6","_uuid":"18be8815e1fb11d7c105bcdce3e1f3dc220a53b2","trusted":false},"cell_type":"code","source":"plt.style.use('seaborn-white')\nholiday_local_type = holiday_events.groupby(['locale_name', 'type']).size()\nholiday_local_type.unstack().plot(kind='bar',stacked=True, colormap= 'magma_r', figsize=(12,10),  grid=False)\nplt.ylabel('Count of entries')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"048ec8b0-a444-4b93-b97a-3891934e256e","_uuid":"a130897eb999c2f15909380f2ed26dd5962574e7","trusted":false},"cell_type":"code","source":"# EDA for items.csv begins here\nitems.head()","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"a0b57e5e-0baa-44cf-a853-f4576ed709d7","_uuid":"bb0afa33f761092b5dd3bd345be17432644cddbc","trusted":false},"cell_type":"code","source":"# BAR PLOT FOR ITEMS V/S FAMILY TYPE\nx, y = (list(x) for x in zip(*sorted(zip(items.family.value_counts().index, \n                                         items.family.value_counts().values), \n                                        reverse = False)))\ntrace2 = go.Bar(\n    y = items.family.value_counts().values,\n    x = items.family.value_counts().index\n)\n\nlayout = dict(\n    title='Counts of items per family category',\n     width = 900, height = 600,\n    yaxis=dict(\n        showgrid = True,\n        showline = True,\n        showticklabels = True\n    ))\n\nfig1 = go.Figure(data=[trace2])\nfig1['layout'].update(layout)\npy.iplot(fig1, filename='plots')","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"43402a66-bc8b-4c78-befd-a976adfbb809","_uuid":"4550e91b7c39d92ed34d627ff18ee15bda2fd885","trusted":false},"cell_type":"code","source":"# Persihable or not \nplt.style.use('seaborn-white')\nfam_perishable = items.groupby(['family', 'perishable']).size()\nfam_perishable.unstack().plot(kind='bar',stacked=True, colormap = 'coolwarm', figsize=(12,10),  grid = True)\nplt.ylabel('count')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"072525b1-ec04-4e95-a927-931e2cf9e6ca","_uuid":"1cd0972f901006b33d9760fab9040a8bf397f26c","trusted":false},"cell_type":"code","source":"# EDA for stores.csv begins here #\nstores.head(3)","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"fc8e82db-fc29-4fd3-a304-c1b01becb6ab","_uuid":"26d8c335ed77ac0058e3d1e78b4d3730bb6046f8","trusted":false},"cell_type":"code","source":"# store distribution across states\nfig, ax = plt.subplots()\nfig.set_size_inches(8, 8)\nax = sns.countplot(y = stores['state'], data = stores) ","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"2d9d72fd-4364-46ea-8a33-5897d2652053","_uuid":"13a168ce7e24934b2789278354ba249f0b10664c","trusted":false},"cell_type":"code","source":"# store distribution across cities\nfig, ax = plt.subplots()\nfig.set_size_inches(8, 8)\nax = sns.countplot(y = stores['city'], data = stores) ","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"82e578ea-ab90-477f-91d9-91dd6f95f642","_uuid":"b6657455bc76faed9f606a2320558ac7288211bd","trusted":false},"cell_type":"code","source":"# Unique state names\nstores.state.unique()","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"67c5b349-5352-4887-b8d7-2c8d16b67037","_uuid":"5b6538a1995ebd311fdc9680cf09c6e1479445c0","trusted":false},"cell_type":"code","source":"# Unique state names\nstores.city.unique()","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"1e11ed34-bbdd-4fb6-a1b2-d256e830541e","_uuid":"158daee93a9f7ac6917b3e750d9e6299149c5eb3","trusted":false},"cell_type":"code","source":"# Various types of stores and their count\nfig, ax = plt.subplots()\nfig.set_size_inches(8, 5)\nax = sns.countplot(x = \"type\", data = stores, palette=\"Paired\")","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"5153da18-a299-4d19-89b4-2445858f01be","_uuid":"6b4aa931ba25cf56a4c539a063c554fa38780ffb","trusted":false},"cell_type":"code","source":"ct = pd.crosstab(stores.state, stores.type)\nct.plot.bar(figsize = (12, 6), stacked=True)\nplt.legend(title='type')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"593bc9b4-dd2a-4938-855f-1072b4f2cfee","_uuid":"1186e5c10b0d47b272509bb48e82d309825d211a","trusted":false},"cell_type":"code","source":"ct = pd.crosstab(stores.city, stores.type)\n\nct.plot.bar(figsize = (12, 6), stacked=True)\nplt.legend(title='type')\n\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"44a747aa-54fd-44a9-bab4-c761da6e3e93","_uuid":"28800d4aeab1c4f8e12d684460b17848f402617e","trusted":false},"cell_type":"code","source":"# total no. of unique stores \nstores.store_nbr.nunique()","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"d61c768e-d85e-4e33-93ea-58e810ec146d","_uuid":"8e607d171930981c5014a0124439a6a7042f6a2c","trusted":false},"cell_type":"code","source":"# total no. of stores (including non-unique)\nstores.cluster.sum()","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"49f28af0-2c7b-4424-93ff-e86163b6ee52","_uuid":"9e24d32d7ec7ec9c0e879e704fb9d739e1455a74","trusted":false},"cell_type":"code","source":"fig, ax = plt.subplots()\nfig.set_size_inches(12, 7)\nax = sns.countplot(x = \"cluster\", data = stores)","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"8354cd2b-2b46-4d10-b909-e76c49fd6d36","_uuid":"7462bbe8c0220f46ed917263eccebf1a1c007e50","trusted":false},"cell_type":"code","source":"# EDA for transactions.csv begins here #\ntransactions.head(3)","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"6c9c9e19-921d-4f89-bc0c-fec02a07492a","_uuid":"7590391d6915671a416b9ceebe03600adfa06005","trusted":false},"cell_type":"code","source":"# Finding out the no.of transactions (rows)\nprint(\"There are {0} transactions\".\n      format(transactions.shape[0], transactions.shape[1]))","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"c4e1330b-f57e-43d7-88ac-e5a67b79edc6","_uuid":"6514a0e76fc749613c7d04567ca84f75fceeddcf","trusted":false},"cell_type":"code","source":"# Time series plot for transaction #\nplt.style.use('seaborn-white')\nplt.figure(figsize=(13,11))\nplt.plot(transactions.date.values, transactions.transactions.values, color='grey')\nplt.axvline(x='2015-12-23',color='red',alpha=0.3)\nplt.axvline(x='2016-12-23',color='red',alpha=0.3)\nplt.axvline(x='2014-12-23',color='red',alpha=0.3)\nplt.axvline(x='2013-12-23',color='red',alpha=0.3)\nplt.axvline(x='2013-05-12',color='green',alpha=0.2, linestyle= '--')\nplt.axvline(x='2015-05-10',color='green',alpha=0.2, linestyle= '--')\nplt.axvline(x='2016-05-08',color='green',alpha=0.2, linestyle= '--')\nplt.axvline(x='2014-05-11',color='green',alpha=0.2, linestyle= '--')\nplt.axvline(x='2017-05-14',color='green',alpha=0.2, linestyle= '--')\nplt.ylabel('Transactions per day', fontsize= 16)\nplt.xlabel('Date', fontsize= 16)\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"fa2810b8-5556-4317-a7b6-0ce33bf06ba5","collapsed":true,"_uuid":"378f1e3f1c497dc64b4212e616844e89e6db9e55","trusted":false},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"},"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"}},"nbformat":4,"nbformat_minor":1}