{"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":{"_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","trusted":true},"cell_type":"code","source":"df = pd.read_csv('../input/train.csv')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"e63a85de9500301e7ca32b80c62d34b78ffc7b42"},"cell_type":"code","source":"df.info()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"d1261e57ae2412e9873e5ae2bc33fc0b26320ca5"},"cell_type":"code","source":"df.head()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a6836401c02a3156c507bd2dee0c2254a2f4a70b"},"cell_type":"code","source":"df['channelGrouping'].unique()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"50056cab1ba2e572783bdb17121e6f76690140cb"},"cell_type":"code","source":"def DeviceSplitter(inputString):\n    theList = inputString.split(',')\n    browser = theList[0].split(\"\\\"\")[-2]\n    OS = theList[3].split(\"\\\"\")[-2]\n    isMobile = theList[5].split(\":\")[-1].strip()\n    deviceCat = theList[-1].split(\"\\\"\")[-2]\n    return ({\"browser\": browser, \"OS\": OS, \"isMobile\": isMobile, \"device\": deviceCat})\n    #return ([browser, OS, isMobile,deviceCat])\n    #print(browser, OS, isMobile, deviceCat)\n    #print(isMobile)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"52d3d0eb91476b46bc3279fb4f881e5b556f1a0d"},"cell_type":"code","source":"DeviceSplitter(df['device'].iloc[0])","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"a69cf0469b2dcd37f3122ea09bbe00f0c1b1deca"},"cell_type":"code","source":"%%time\nrandom_row = df['device'].apply(DeviceSplitter)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"2338e08883fcb75572543fc17f91b1ae646c9461"},"cell_type":"code","source":"from sklearn.feature_extraction import FeatureHasher\nrandom_row","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"7f63df1dfbb1ff06438183e8379491d4da28588e"},"cell_type":"code","source":"h = FeatureHasher(n_features=5)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"c4e6b6866274b130d72ed154d54f1d95267df374"},"cell_type":"code","source":"f1 = h.fit_transform(random_row)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"_uuid":"4cb37dcbd33649f098862dc49a1f0e16dc36a0e0"},"cell_type":"code","source":"pd.concat([pd.DataFrame(f1.toarray()), random_row], axis = 1)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true,"collapsed":true,"_uuid":"7442f47bcd68765eb988d9231eb2176aa0fb4449"},"cell_type":"code","source":"def ","execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"display_name":"Python 3","language":"python","name":"python3"},"language_info":{"name":"python","version":"3.6.4","mimetype":"text/x-python","codemirror_mode":{"name":"ipython","version":3},"pygments_lexer":"ipython3","nbconvert_exporter":"python","file_extension":".py"}},"nbformat":4,"nbformat_minor":1}