{"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\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 read-only \"../input/\" directory\n# For example, running this (by clicking run or pressing Shift+Enter) will list all files under the input directory\n\nimport os\nfor dirname, _, filenames in os.walk('/kaggle/input'):\n    for filename in filenames:\n        print(os.path.join(dirname, filename))\n\n# You can write up to 5GB to the current directory (/kaggle/working/) that gets preserved as output when you create a version using \"Save & Run All\" \n# You can also write temporary files to /kaggle/temp/, but they won't be saved outside of the current session","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"# Bosch-DATE","execution_count":null},{"metadata":{"trusted":true},"cell_type":"code","source":"df=pd.read_csv('/kaggle/input/bosch-production-line-performance/train_date.csv.zip',nrows=100)\ndf.info()","execution_count":null,"outputs":[]},{"metadata":{"_uuid":"d629ff2d2480ee46fbb7e2d37f6b5fab8052498a","_cell_guid":"79c7e3d0-c299-4dcb-8224-4455121ee9b0","trusted":true},"cell_type":"code","source":"size = 100000\nflag = 0\nstations =[]\nstation_name='S0'\nfor i in pd.read_csv('/kaggle/input/bosch-production-line-performance/train_date.csv.zip',iterator=True, chunksize=size,compression='zip'):\n    #reset all the values for next iteration\n    print('new iteration')\n    if (station_name == 'S52' ):\n        #print('fun with flags')\n        flag = 1\n    i.insert(loc=1157,column= 'finito',value=0)\n    a=i.columns\n    #Id = i.loc[:,'Id']\n    station_counter = 0\n    feature_counter = 0\n    cumulative_feature = 0\n    index=0\n    station_name = 'S{}'.format(station_counter)\n    while flag == 0 :\n        feature_counter = 0\n        while station_name in a[index+1]:\n            index+=1\n            feature_counter+=1\n        print(feature_counter)\n        cumulative_feature += feature_counter\n        newframe = i.iloc[:,cumulative_feature-feature_counter+1:cumulative_feature+1] \n        #newframe.insert(loc = 0, column'Id')\n        #newframe.insert(loc=2141,column= 'finito',value=0) \n        newframe.insert(0,\"Id\",i.iloc[ :,0],True)\n        newframe = newframe.dropna( thresh = 2)\n        newframe.to_csv(station_name+'_date.csv',index = False)\n        station_counter+=1\n        print(station_name)\n        stations.append(station_name)\n        station_name = 'S{}'.format(station_counter)\n        if(station_name == 'S52'):\n            print('passing to second is now')\n            station_counter = 0\n            feature_counter = 0\n            cumulative_feature = 0\n            break\n        while station_name not in a[index+1]:\n            print('wel wel wel')\n            station_counter+=1\n            station_name = 'S{}'.format(station_counter)\n    while(flag == 1) and (len(i) != 0):\n        feature_counter = 0\n        while station_name in a[index+1]:\n            index+=1\n            feature_counter+=1\n        cumulative_feature+=feature_counter\n        newframe = i.iloc[:,cumulative_feature-feature_counter+1:cumulative_feature+1] \n        #newframe.insert(loc=2141,column= 'finito',value=0) \n        newframe.insert(0,\"Id\",i.iloc[ :,0],True)\n        newframe = newframe.dropna( thresh = 2)\n        newframe.to_csv(station_name+'_date.csv',header = False,index = False,mode = 'a')\n        station_counter+=1\n        #print(station_name)\n        station_name = 'S{}'.format(station_counter)\n        if station_name =='S52':\n            break\n        while station_name not in a[index+1]:\n            #print('wo')\n            station_counter+=1\n            station_name = 'S{}'.format(station_counter)\n              \nprint('done done done')","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"#empty consist of all the stations as keys and total number of missing data per station as values\nempty = {}\nfor i in stations:\n    df = pd.read_csv( i+'_date.csv')\n    empty[i] = df.isna().sum().sum()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"empty","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"terminal = stations[len(stations)-1]\n# Feature Dictionnary 'FeatureName' : '# of Nan ' \nFeatures = {}\nfor i in stations:\n    df = pd.read_csv( i+'_date.csv')\n    counter = 1\n    while(True):\n        SerieOfFeature= df.iloc[:,counter]\n        Null_per_Feature = SerieOfFeature.isnull().sum()\n        Features[df.columns[counter]] = Null_per_Feature\n        counter+=1\n        if counter > len(df.columns)-1:\n            break","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"Features","execution_count":null,"outputs":[]}],"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":4,"nbformat_minor":4}