{"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":"import pandas as pd\nimport cudf\nimport time\nprint(f\"Pandas: {pd.__version__}, Cudf: {cudf.__version__}\")","metadata":{"execution":{"iopub.status.busy":"2022-05-11T13:30:26.508254Z","iopub.execute_input":"2022-05-11T13:30:26.509115Z","iopub.status.idle":"2022-05-11T13:30:29.365663Z","shell.execute_reply.started":"2022-05-11T13:30:26.509003Z","shell.execute_reply":"2022-05-11T13:30:29.364465Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Lets load the dataframe in pandas and cudf","metadata":{}},{"cell_type":"code","source":"starttime = time.time()\ndf_pandas = pd.read_csv('../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')\ntime_pandas = time.time() - starttime\nprint(f\"Time to load: {time_pandas:.2f}s\")\n\nprint(df_pandas.shape)\ndf_pandas.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-11T13:30:33.593004Z","iopub.execute_input":"2022-05-11T13:30:33.593974Z","iopub.status.idle":"2022-05-11T13:31:06.485288Z","shell.execute_reply.started":"2022-05-11T13:30:33.593923Z","shell.execute_reply":"2022-05-11T13:31:06.484485Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"starttime = time.time()\ndf_cudf = cudf.read_csv('../input/h-and-m-personalized-fashion-recommendations/transactions_train.csv')\ntime_cudf = time.time() - starttime\nprint(f\"Time to load: {time_cudf:.2f}s\")\n\nprint(df_cudf.shape)\ndf_cudf.head()","metadata":{"execution":{"iopub.status.busy":"2022-05-11T13:31:06.486975Z","iopub.execute_input":"2022-05-11T13:31:06.487416Z","iopub.status.idle":"2022-05-11T13:31:09.609153Z","shell.execute_reply.started":"2022-05-11T13:31:06.487376Z","shell.execute_reply":"2022-05-11T13:31:09.608415Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print( f\"Cudf is {time_pandas/time_cudf} times faster for loading this dataset.\")","metadata":{"execution":{"iopub.status.busy":"2022-05-11T13:31:34.351500Z","iopub.execute_input":"2022-05-11T13:31:34.352047Z","iopub.status.idle":"2022-05-11T13:31:34.356709Z","shell.execute_reply.started":"2022-05-11T13:31:34.351996Z","shell.execute_reply":"2022-05-11T13:31:34.355891Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Now lets sort it","metadata":{}},{"cell_type":"code","source":"starttime = time.time()\ndf_pandas = df_pandas.sort_values('t_dat', ignore_index=True)\ntime_pandas = time.time() - starttime\nprint(f\"Time to sort: {time_pandas:.2f}s\")","metadata":{"execution":{"iopub.status.busy":"2022-05-11T13:31:39.753475Z","iopub.execute_input":"2022-05-11T13:31:39.754036Z","iopub.status.idle":"2022-05-11T13:32:23.846134Z","shell.execute_reply.started":"2022-05-11T13:31:39.753995Z","shell.execute_reply":"2022-05-11T13:32:23.844403Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"starttime = time.time()\ndf_cudf = df_cudf.sort_values('t_dat', ignore_index=True)\ntime_cudf = time.time() - starttime\nprint(f\"Time to sort: {time_cudf:.2f}s\")","metadata":{"execution":{"iopub.status.busy":"2022-05-11T13:32:23.847958Z","iopub.execute_input":"2022-05-11T13:32:23.848349Z","iopub.status.idle":"2022-05-11T13:32:24.660871Z","shell.execute_reply.started":"2022-05-11T13:32:23.848307Z","shell.execute_reply":"2022-05-11T13:32:24.659895Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print( f\"Cudf is {time_pandas/time_cudf} times faster to sort this dataset.\")","metadata":{"execution":{"iopub.status.busy":"2022-05-11T13:32:24.662391Z","iopub.execute_input":"2022-05-11T13:32:24.662833Z","iopub.status.idle":"2022-05-11T13:32:24.669169Z","shell.execute_reply.started":"2022-05-11T13:32:24.662790Z","shell.execute_reply":"2022-05-11T13:32:24.668361Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"# Making aggregations","metadata":{}},{"cell_type":"code","source":"starttime = time.time()\nagg_pandas = df_pandas.groupby('customer_id')[['price', 'sales_channel_id']].agg(['mean', 'min', 'max', 'std'])\ntime_pandas = time.time() - starttime\nprint(f\"Time to aggregate: {time_pandas:.2f}s\")","metadata":{"execution":{"iopub.status.busy":"2022-05-11T13:33:12.765365Z","iopub.execute_input":"2022-05-11T13:33:12.765692Z","iopub.status.idle":"2022-05-11T13:33:30.101720Z","shell.execute_reply.started":"2022-05-11T13:33:12.765660Z","shell.execute_reply":"2022-05-11T13:33:30.100812Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"starttime = time.time()\nagg_cudf = df_cudf.groupby('customer_id')[['price', 'sales_channel_id']].agg(['mean', 'min', 'max', 'std'])\ntime_cudf = time.time() - starttime\nprint(f\"Time to aggregate: {time_cudf:.2f}s\")","metadata":{"execution":{"iopub.status.busy":"2022-05-11T13:33:37.457516Z","iopub.execute_input":"2022-05-11T13:33:37.458015Z","iopub.status.idle":"2022-05-11T13:33:38.037542Z","shell.execute_reply.started":"2022-05-11T13:33:37.457974Z","shell.execute_reply":"2022-05-11T13:33:38.036754Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"print( f\"Cudf is {time_pandas/time_cudf} times faster to agregate this dataset.\")","metadata":{"execution":{"iopub.status.busy":"2022-05-11T13:33:43.141260Z","iopub.execute_input":"2022-05-11T13:33:43.141854Z","iopub.status.idle":"2022-05-11T13:33:43.147875Z","shell.execute_reply.started":"2022-05-11T13:33:43.141805Z","shell.execute_reply":"2022-05-11T13:33:43.146834Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}