{"metadata":{"kernelspec":{"language":"python","display_name":"Python 3","name":"python3"},"language_info":{"pygments_lexer":"ipython3","nbconvert_exporter":"python","version":"3.6.4","file_extension":".py","codemirror_mode":{"name":"ipython","version":3},"name":"python","mimetype":"text/x-python"}},"nbformat_minor":4,"nbformat":4,"cells":[{"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python Docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load\n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\n\n\n# 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\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-04-17T07:51:04.731154Z","iopub.execute_input":"2022-04-17T07:51:04.731509Z","iopub.status.idle":"2022-04-17T07:51:04.737860Z","shell.execute_reply.started":"2022-04-17T07:51:04.731472Z","shell.execute_reply":"2022-04-17T07:51:04.736661Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"!pip install bar_chart_race","metadata":{"execution":{"iopub.status.busy":"2022-04-17T07:51:04.861243Z","iopub.execute_input":"2022-04-17T07:51:04.861563Z","iopub.status.idle":"2022-04-17T07:51:17.261847Z","shell.execute_reply.started":"2022-04-17T07:51:04.861528Z","shell.execute_reply":"2022-04-17T07:51:17.260647Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')","metadata":{"execution":{"iopub.status.busy":"2022-04-17T07:51:17.264224Z","iopub.execute_input":"2022-04-17T07:51:17.265322Z","iopub.status.idle":"2022-04-17T07:52:17.613020Z","shell.execute_reply.started":"2022-04-17T07:51:17.265273Z","shell.execute_reply":"2022-04-17T07:52:17.611769Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['t_dat']=pd.to_datetime(df['t_dat'])","metadata":{"execution":{"iopub.status.busy":"2022-04-17T07:52:17.614829Z","iopub.execute_input":"2022-04-17T07:52:17.615142Z","iopub.status.idle":"2022-04-17T07:52:23.996244Z","shell.execute_reply.started":"2022-04-17T07:52:17.615106Z","shell.execute_reply":"2022-04-17T07:52:23.995040Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df['week']=(df['t_dat']-df['t_dat'].min()).dt.days//7","metadata":{"execution":{"iopub.status.busy":"2022-04-17T07:52:23.999473Z","iopub.execute_input":"2022-04-17T07:52:24.000100Z","iopub.status.idle":"2022-04-17T07:52:25.183257Z","shell.execute_reply.started":"2022-04-17T07:52:24.000043Z","shell.execute_reply":"2022-04-17T07:52:25.182463Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mt_3000=df['article_id'].value_counts().loc[df['article_id'].value_counts() > 3000].index","metadata":{"execution":{"iopub.status.busy":"2022-04-17T07:52:25.184657Z","iopub.execute_input":"2022-04-17T07:52:25.185009Z","iopub.status.idle":"2022-04-17T07:52:29.208999Z","shell.execute_reply.started":"2022-04-17T07:52:25.184960Z","shell.execute_reply":"2022-04-17T07:52:29.207932Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count_items=df[df['article_id'].isin(mt_3000)][['week','article_id','sales_channel_id']].pivot_table(index='week',columns='article_id',aggfunc='count')","metadata":{"execution":{"iopub.status.busy":"2022-04-17T07:52:29.210833Z","iopub.execute_input":"2022-04-17T07:52:29.211558Z","iopub.status.idle":"2022-04-17T07:52:31.869480Z","shell.execute_reply.started":"2022-04-17T07:52:29.211501Z","shell.execute_reply":"2022-04-17T07:52:31.867514Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count_items=count_items['sales_channel_id']","metadata":{"execution":{"iopub.status.busy":"2022-04-17T07:52:31.871191Z","iopub.execute_input":"2022-04-17T07:52:31.871516Z","iopub.status.idle":"2022-04-17T07:52:31.879139Z","shell.execute_reply.started":"2022-04-17T07:52:31.871477Z","shell.execute_reply":"2022-04-17T07:52:31.878341Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count_items.fillna(0,inplace=True)","metadata":{"execution":{"iopub.status.busy":"2022-04-17T07:52:31.880462Z","iopub.execute_input":"2022-04-17T07:52:31.881003Z","iopub.status.idle":"2022-04-17T07:52:31.901698Z","shell.execute_reply.started":"2022-04-17T07:52:31.880942Z","shell.execute_reply":"2022-04-17T07:52:31.900035Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import bar_chart_race as bcr","metadata":{"execution":{"iopub.status.busy":"2022-04-17T07:52:31.903619Z","iopub.execute_input":"2022-04-17T07:52:31.905010Z","iopub.status.idle":"2022-04-17T07:52:31.915771Z","shell.execute_reply.started":"2022-04-17T07:52:31.904943Z","shell.execute_reply":"2022-04-17T07:52:31.914817Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"count_items.head()","metadata":{"execution":{"iopub.status.busy":"2022-04-17T07:52:31.919203Z","iopub.execute_input":"2022-04-17T07:52:31.919965Z","iopub.status.idle":"2022-04-17T07:52:31.970351Z","shell.execute_reply.started":"2022-04-17T07:52:31.919908Z","shell.execute_reply":"2022-04-17T07:52:31.969222Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import warnings\nwarnings.filterwarnings(\"ignore\")","metadata":{"execution":{"iopub.status.busy":"2022-04-17T08:04:10.093571Z","iopub.execute_input":"2022-04-17T08:04:10.093926Z","iopub.status.idle":"2022-04-17T08:04:10.099308Z","shell.execute_reply.started":"2022-04-17T08:04:10.093885Z","shell.execute_reply":"2022-04-17T08:04:10.098108Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bcr.bar_chart_race(df=count_items, filename=None, steps_per_period=20, n_bars=12,filter_column_colors=True, period_length=2000,\n                   shared_fontdict={'family': 'sans-serif', 'weight': 'bold',\n                                    'color': 'rebeccapurple'})","metadata":{"execution":{"iopub.status.busy":"2022-04-17T08:04:11.483442Z","iopub.execute_input":"2022-04-17T08:04:11.483801Z","iopub.status.idle":"2022-04-17T08:04:51.884330Z","shell.execute_reply.started":"2022-04-17T08:04:11.483766Z","shell.execute_reply":"2022-04-17T08:04:51.883107Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"bcr.bar_chart_race(df=count_items, filename='top12_sales.mp4', steps_per_period=20, n_bars=12, period_length=2000,filter_column_colors=True)","metadata":{"execution":{"iopub.status.busy":"2022-04-17T07:53:10.529951Z","iopub.execute_input":"2022-04-17T07:53:10.530287Z","iopub.status.idle":"2022-04-17T07:56:43.575708Z","shell.execute_reply.started":"2022-04-17T07:53:10.530244Z","shell.execute_reply":"2022-04-17T07:56:43.573448Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}