{"cells":[{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true},"cell_type":"code","source":"# This Python 3 environment comes with many helpful analytics libraries installed\n# It is defined by the kaggle/python docker image: https://github.com/kaggle/docker-python\n# For example, here's several helpful packages to load in \n\nimport numpy as np # linear algebra\nimport pandas as pd # data processing, CSV file I/O (e.g. pd.read_csv)\n\n# Input data files are available in the \"../input/\" directory.\n# For example, running this (by clicking run or pressing Shift+Enter) will list the files in the input directory\n\nimport os\nprint(os.listdir(\"../input\"))\n\n# Any results you write to the current directory are saved as output.","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d83b4732db190db575100e6bf1620d059962e5a4"},"cell_type":"code","source":"from pandas.io.json import json_normalize","execution_count":null,"outputs":[]},{"metadata":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"JSON_COLUMNS = ['device', 'geoNetwork', 'totals', 'trafficSource']\ntrain = pd.read_csv('../input/train.csv', converters={column:json.loads for column in JSON_COLUMNS}, \n                   dtype={'fullVisitorId': 'str'})","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"scrolled":true,"_uuid":"89bb374cae132421e6306f18dabc65d48b3b0a72"},"cell_type":"code","source":"train.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"fd2c6183554461a76317a89277117dac4c204373"},"cell_type":"code","source":"pd.options.display.max_columns = 1000\npd.options.display.max_rows = 1000","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e003390834fe1e2a653ed30a295d988ec3d8d807"},"cell_type":"code","source":"for column in JSON_COLUMNS:\n    columns_df = json_normalize(train[column])\n    columns_df.columns = [f\"{column}_{subcolumn}\" for subcolumn in columns_df.columns]\n    train = train.drop(column, axis=1).merge(columns_df, right_index=True, left_index=True)\n#     print(columns_df.head())","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"9bc009f37eda889b9ac99434e0bd3740a9b95e7b"},"cell_type":"code","source":"train.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"356a4484d3b13b20c31895c0e2eb47e701adea1d"},"cell_type":"code","source":"","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.6","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}