{"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":"2023-06-05T10:14:43.832327Z","iopub.execute_input":"2023-06-05T10:14:43.832830Z","iopub.status.idle":"2023-06-05T10:14:47.401295Z","shell.execute_reply.started":"2023-06-05T10:14:43.832703Z","shell.execute_reply":"2023-06-05T10:14:47.399664Z"},"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":"2023-06-05T10:14:47.403148Z","iopub.execute_input":"2023-06-05T10:14:47.403493Z","iopub.status.idle":"2023-06-05T10:15:43.171753Z","shell.execute_reply.started":"2023-06-05T10:14:47.403453Z","shell.execute_reply":"2023-06-05T10:15:43.170948Z"},"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":"2023-06-05T10:15:43.173408Z","iopub.execute_input":"2023-06-05T10:15:43.173939Z","iopub.status.idle":"2023-06-05T10:15:47.520625Z","shell.execute_reply.started":"2023-06-05T10:15:43.173882Z","shell.execute_reply":"2023-06-05T10:15:47.519665Z"},"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":"2023-06-05T10:15:47.522237Z","iopub.execute_input":"2023-06-05T10:15:47.522600Z","iopub.status.idle":"2023-06-05T10:15:47.529331Z","shell.execute_reply.started":"2023-06-05T10:15:47.522559Z","shell.execute_reply":"2023-06-05T10:15:47.528449Z"},"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":"2023-06-05T10:15:47.532501Z","iopub.execute_input":"2023-06-05T10:15:47.533323Z","iopub.status.idle":"2023-06-05T10:16:27.493714Z","shell.execute_reply.started":"2023-06-05T10:15:47.533273Z","shell.execute_reply":"2023-06-05T10:16:27.492790Z"},"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":"2023-06-05T10:16:27.495141Z","iopub.execute_input":"2023-06-05T10:16:27.495578Z","iopub.status.idle":"2023-06-05T10:16:28.315292Z","shell.execute_reply.started":"2023-06-05T10:16:27.495539Z","shell.execute_reply":"2023-06-05T10:16:28.313700Z"},"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":"2023-06-05T10:16:28.316806Z","iopub.execute_input":"2023-06-05T10:16:28.317157Z","iopub.status.idle":"2023-06-05T10:16:28.322557Z","shell.execute_reply.started":"2023-06-05T10:16:28.317110Z","shell.execute_reply":"2023-06-05T10:16:28.321353Z"},"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":"2023-06-05T10:16:28.324390Z","iopub.execute_input":"2023-06-05T10:16:28.325003Z","iopub.status.idle":"2023-06-05T10:16:45.528197Z","shell.execute_reply.started":"2023-06-05T10:16:28.324965Z","shell.execute_reply":"2023-06-05T10:16:45.526954Z"},"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":"2023-06-05T10:16:45.529797Z","iopub.execute_input":"2023-06-05T10:16:45.530585Z","iopub.status.idle":"2023-06-05T10:16:46.125535Z","shell.execute_reply.started":"2023-06-05T10:16:45.530546Z","shell.execute_reply":"2023-06-05T10:16:46.124614Z"},"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":"2023-06-05T10:16:46.127017Z","iopub.execute_input":"2023-06-05T10:16:46.127317Z","iopub.status.idle":"2023-06-05T10:16:46.132648Z","shell.execute_reply.started":"2023-06-05T10:16:46.127278Z","shell.execute_reply":"2023-06-05T10:16:46.131814Z"},"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":[]}]}