{"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":"markdown","source":"A slight modification of the notebook, \"[Read a chunk of jsonl](https://www.kaggle.com/code/inversion/read-a-chunk-of-jsonl)\", converts it to a more manageable DataFrame.","metadata":{}},{"cell_type":"code","source":"import numpy as np\nimport pandas as pd\n\nfrom pathlib import Path\n\ndata_path = Path('/kaggle/input/otto-recommender-system/')","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-11-02T03:27:14.454634Z","iopub.execute_input":"2022-11-02T03:27:14.455839Z","iopub.status.idle":"2022-11-02T03:27:14.485931Z","shell.execute_reply.started":"2022-11-02T03:27:14.455690Z","shell.execute_reply":"2022-11-02T03:27:14.484983Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_sessions = pd.DataFrame()\nchunks = pd.read_json(data_path / 'train.jsonl', lines=True, chunksize=100_000)\n\nfor e, chunk in enumerate(chunks):\n    event_dict = {\n        'session': [],\n        'aid': [],\n        'ts': [],\n        'type': [],\n    }\n    if e < 2:\n        # train_sessions = pd.concat([train_sessions, chunk])\n        for session, events in zip(chunk['session'].tolist(), chunk['events'].tolist()):\n            for event in events:\n                event_dict['session'].append(session)\n                event_dict['aid'].append(event['aid'])\n                event_dict['ts'].append(event['ts'])\n                event_dict['type'].append(event['type'])\n        chunk_session = pd.DataFrame(event_dict)\n        train_sessions = pd.concat([train_sessions, chunk_session])\n    else:\n        break\n        \ntrain_sessions = train_sessions.reset_index(drop=True)","metadata":{"execution":{"iopub.status.busy":"2022-11-02T03:27:25.564759Z","iopub.execute_input":"2022-11-02T03:27:25.565186Z","iopub.status.idle":"2022-11-02T03:28:19.865952Z","shell.execute_reply.started":"2022-11-02T03:27:25.565148Z","shell.execute_reply":"2022-11-02T03:28:19.864440Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"display(train_sessions)","metadata":{"execution":{"iopub.status.busy":"2022-11-02T03:29:19.285874Z","iopub.execute_input":"2022-11-02T03:29:19.287742Z","iopub.status.idle":"2022-11-02T03:29:19.319864Z","shell.execute_reply.started":"2022-11-02T03:29:19.287656Z","shell.execute_reply":"2022-11-02T03:29:19.318604Z"},"trusted":true},"execution_count":null,"outputs":[]}]}