{"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 modules\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","execution":{"iopub.status.busy":"2022-11-02T11:45:32.155366Z","iopub.execute_input":"2022-11-02T11:45:32.156287Z","iopub.status.idle":"2022-11-02T11:45:32.195262Z","shell.execute_reply.started":"2022-11-02T11:45:32.156160Z","shell.execute_reply":"2022-11-02T11:45:32.193886Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"import json\n  \n# Opening JSON file\ndata_path = '/kaggle/input/otto-recommender-system/train.jsonl'\n  \ntrain_sessions = pd.DataFrame()\nchunks = pd.read_json(data_path, 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-02T11:50:37.836875Z","iopub.execute_input":"2022-11-02T11:50:37.837385Z","iopub.status.idle":"2022-11-02T11:51:36.240721Z","shell.execute_reply.started":"2022-11-02T11:50:37.837347Z","shell.execute_reply":"2022-11-02T11:51:36.239504Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_sessions.head(5)","metadata":{},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"","metadata":{},"execution_count":null,"outputs":[]}]}