{"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":"# Because of RAM constraint we have to work on test data\nimport pandas as pd\nfile_path=\"/kaggle/input/otto-recommender-system/test.jsonl\"\ndf = pd.read_json(path_or_buf=file_path, lines=True)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T15:45:40.259345Z","iopub.execute_input":"2022-11-13T15:45:40.260473Z","iopub.status.idle":"2022-11-13T15:46:01.941948Z","shell.execute_reply.started":"2022-11-13T15:45:40.260420Z","shell.execute_reply":"2022-11-13T15:46:01.940840Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"def buildDataFrame(dfs):\n    \n    list_tuples=[]\n    for s in range(dfs.shape[0]):\n        sessionId=dfs.iloc[s,0]\n        for aid in range(0, len(dfs.iloc[s,1])):\n            list_tuples.append((sessionId,\n                                dfs.iloc[s,1][aid]['aid'],\n                                dfs.iloc[s,1][aid]['ts'], \n                                dfs.iloc[s,1][aid]['type']))\n\n\n    return pd.DataFrame.from_records(list_tuples, \n                              columns = [\"session\", \"aid\", \"ts\", \"type\"])\n    \n   ","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dfs=df.head(1000)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T15:46:56.054965Z","iopub.execute_input":"2022-11-13T15:46:56.055392Z","iopub.status.idle":"2022-11-13T15:46:56.060491Z","shell.execute_reply.started":"2022-11-13T15:46:56.055356Z","shell.execute_reply":"2022-11-13T15:46:56.059260Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df.shape","metadata":{"execution":{"iopub.status.busy":"2022-11-13T14:16:53.946518Z","iopub.execute_input":"2022-11-13T14:16:53.947017Z","iopub.status.idle":"2022-11-13T14:16:53.955358Z","shell.execute_reply.started":"2022-11-13T14:16:53.946973Z","shell.execute_reply":"2022-11-13T14:16:53.954148Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(df.iloc[3,1])","metadata":{"execution":{"iopub.status.busy":"2022-11-13T14:24:36.979752Z","iopub.execute_input":"2022-11-13T14:24:36.980134Z","iopub.status.idle":"2022-11-13T14:24:36.986669Z","shell.execute_reply.started":"2022-11-13T14:24:36.980101Z","shell.execute_reply":"2022-11-13T14:24:36.985618Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"max((len(df.iloc[i,1]) for i in range(df.shape[0])))","metadata":{"execution":{"iopub.status.busy":"2022-11-13T14:27:22.778731Z","iopub.execute_input":"2022-11-13T14:27:22.779141Z","iopub.status.idle":"2022-11-13T14:28:08.309277Z","shell.execute_reply.started":"2022-11-13T14:27:22.779103Z","shell.execute_reply":"2022-11-13T14:28:08.308178Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#min((len(df.iloc[i,1]) for i in range(df.shape[0])))","metadata":{"execution":{"iopub.status.busy":"2022-11-13T14:28:23.234031Z","iopub.execute_input":"2022-11-13T14:28:23.235111Z","iopub.status.idle":"2022-11-13T14:28:23.239985Z","shell.execute_reply.started":"2022-11-13T14:28:23.235070Z","shell.execute_reply":"2022-11-13T14:28:23.238905Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"#pd.DataFrame.from_records?","metadata":{"execution":{"iopub.status.busy":"2022-11-13T15:37:26.749345Z","iopub.execute_input":"2022-11-13T15:37:26.749728Z","iopub.status.idle":"2022-11-13T15:37:26.754722Z","shell.execute_reply.started":"2022-11-13T15:37:26.749697Z","shell.execute_reply":"2022-11-13T15:37:26.753572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":" ","metadata":{"execution":{"iopub.status.busy":"2022-11-13T15:43:24.812174Z","iopub.execute_input":"2022-11-13T15:43:24.813156Z","iopub.status.idle":"2022-11-13T15:43:24.820660Z","shell.execute_reply.started":"2022-11-13T15:43:24.813117Z","shell.execute_reply":"2022-11-13T15:43:24.819462Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sample=buildDataFrame(dfs)","metadata":{"execution":{"iopub.status.busy":"2022-11-13T15:47:32.306011Z","iopub.execute_input":"2022-11-13T15:47:32.306425Z","iopub.status.idle":"2022-11-13T15:47:32.969107Z","shell.execute_reply.started":"2022-11-13T15:47:32.306392Z","shell.execute_reply":"2022-11-13T15:47:32.968120Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sample.tail()","metadata":{"execution":{"iopub.status.busy":"2022-11-13T15:47:36.907485Z","iopub.execute_input":"2022-11-13T15:47:36.908089Z","iopub.status.idle":"2022-11-13T15:47:36.919129Z","shell.execute_reply.started":"2022-11-13T15:47:36.908051Z","shell.execute_reply":"2022-11-13T15:47:36.918093Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sample.shape","metadata":{"execution":{"iopub.status.busy":"2022-11-13T15:47:48.867745Z","iopub.execute_input":"2022-11-13T15:47:48.868279Z","iopub.status.idle":"2022-11-13T15:47:48.877136Z","shell.execute_reply.started":"2022-11-13T15:47:48.868190Z","shell.execute_reply":"2022-11-13T15:47:48.875931Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"df_sample.type.value_counts()","metadata":{"execution":{"iopub.status.busy":"2022-11-13T15:55:00.073146Z","iopub.execute_input":"2022-11-13T15:55:00.073580Z","iopub.status.idle":"2022-11-13T15:55:00.089065Z","shell.execute_reply.started":"2022-11-13T15:55:00.073544Z","shell.execute_reply":"2022-11-13T15:55:00.087861Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"len(df_sample.aid.unique())","metadata":{"execution":{"iopub.status.busy":"2022-11-13T15:56:13.749890Z","iopub.execute_input":"2022-11-13T15:56:13.750358Z","iopub.status.idle":"2022-11-13T15:56:13.759731Z","shell.execute_reply.started":"2022-11-13T15:56:13.750311Z","shell.execute_reply":"2022-11-13T15:56:13.758572Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import matplotlib as plt\n%matplotlib inline\n","metadata":{"execution":{"iopub.status.busy":"2022-11-13T15:48:28.421728Z","iopub.execute_input":"2022-11-13T15:48:28.422147Z","iopub.status.idle":"2022-11-13T15:48:28.428162Z","shell.execute_reply.started":"2022-11-13T15:48:28.422113Z","shell.execute_reply":"2022-11-13T15:48:28.426934Z"},"trusted":true},"execution_count":null,"outputs":[]}]}