{"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":"# introduction\n\nI visualize the missing value for cryptocurrency.  \nYou will find that the number of missing data and the location is imbalanced according to the type of the cryptocurrency.  \nIf you find the notebook is interesting or helpful, please upvote👍","metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19"}},{"cell_type":"code","source":"import pandas as pd\nimport seaborn as sns\nimport matplotlib.pyplot as plt\nimport matplotlib as mpl","metadata":{"execution":{"iopub.status.busy":"2021-12-02T14:03:42.552421Z","iopub.execute_input":"2021-12-02T14:03:42.552802Z","iopub.status.idle":"2021-12-02T14:03:43.615285Z","shell.execute_reply.started":"2021-12-02T14:03:42.552705Z","shell.execute_reply":"2021-12-02T14:03:43.614331Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"mpl.rcParams['axes.grid'] = False","metadata":{"execution":{"iopub.status.busy":"2021-12-02T14:03:43.61723Z","iopub.execute_input":"2021-12-02T14:03:43.617692Z","iopub.status.idle":"2021-12-02T14:03:43.623152Z","shell.execute_reply.started":"2021-12-02T14:03:43.617655Z","shell.execute_reply":"2021-12-02T14:03:43.622085Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"asset_df = pd.read_csv('../input/g-research-crypto-forecasting/asset_details.csv')","metadata":{"execution":{"iopub.status.busy":"2021-12-02T14:03:43.624986Z","iopub.execute_input":"2021-12-02T14:03:43.625697Z","iopub.status.idle":"2021-12-02T14:03:43.648736Z","shell.execute_reply.started":"2021-12-02T14:03:43.625642Z","shell.execute_reply":"2021-12-02T14:03:43.647732Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"train_df = pd.read_csv('../input/g-research-crypto-forecasting/train.csv')\n# train_df.info()\ntrain_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-02T14:03:43.650577Z","iopub.execute_input":"2021-12-02T14:03:43.650901Z","iopub.status.idle":"2021-12-02T14:04:46.610247Z","shell.execute_reply.started":"2021-12-02T14:03:43.650855Z","shell.execute_reply":"2021-12-02T14:04:46.60926Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"sorted_train_df = train_df.sort_values(['Asset_ID','timestamp'])\n# sorted_train_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-02T14:04:46.612358Z","iopub.execute_input":"2021-12-02T14:04:46.612594Z","iopub.status.idle":"2021-12-02T14:05:01.041115Z","shell.execute_reply.started":"2021-12-02T14:04:46.612565Z","shell.execute_reply":"2021-12-02T14:05:01.040037Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"dropped_sorted_train_df = sorted_train_df.drop(columns=['timestamp','Count','Open','High','Low','Close','Volume','VWAP'])\n# dropped_sorted_train_df.head()","metadata":{"execution":{"iopub.status.busy":"2021-12-02T14:05:01.042482Z","iopub.execute_input":"2021-12-02T14:05:01.042965Z","iopub.status.idle":"2021-12-02T14:05:01.281687Z","shell.execute_reply.started":"2021-12-02T14:05:01.042934Z","shell.execute_reply":"2021-12-02T14:05:01.280733Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"code","source":"missing_ratio_lst = []\nasset_name_lst = []\n\nfor asset_id in range(13):\n    target_df = dropped_sorted_train_df[dropped_sorted_train_df['Asset_ID']==asset_id]\n    n_data = len(target_df)\n    n_miss = target_df['Target'].isnull().sum()\n    ratio = n_miss / n_data * 100\n    asset_name = asset_df[asset_df[\"Asset_ID\"]==asset_id][\"Asset_Name\"].values[0]\n    \n    asset_name_lst.append(asset_name)\n    missing_ratio_lst.append(ratio)\n    \n    # print(asset_id,asset_name,n_data,ratio)\n\nmpl.rcParams['figure.figsize'] = (12, 8)\nmissing_ratio_df = pd.DataFrame(list(zip(asset_name_lst,missing_ratio_lst)), columns = ['Asset_Name','Missing_rate[%]'])\nmissing_ratio_df = missing_ratio_df.sort_values(['Missing_rate[%]'])\nmissing_ratio_df.plot.bar(x='Asset_Name',rot = 70)","metadata":{"execution":{"iopub.status.busy":"2021-12-02T14:09:10.133659Z","iopub.execute_input":"2021-12-02T14:09:10.134408Z","iopub.status.idle":"2021-12-02T14:09:11.36401Z","shell.execute_reply.started":"2021-12-02T14:09:10.134346Z","shell.execute_reply":"2021-12-02T14:09:11.363272Z"},"trusted":true},"execution_count":null,"outputs":[]},{"cell_type":"markdown","source":"Becareful.  \nBitcoin, Ethereum and Litecoin also has a little missing data.  ","metadata":{}},{"cell_type":"code","source":"mpl.rcParams['figure.figsize'] = (30, 2)\nfor asset_id in range(14):\n    target_df = dropped_sorted_train_df[dropped_sorted_train_df['Asset_ID']==asset_id]\n    target_df = target_df.drop(columns=['Asset_ID']).reset_index(drop=True)\n    asset_name = asset_df[asset_df[\"Asset_ID\"]==asset_id][\"Asset_Name\"].values[0]\n\n    ax = plt.axes()\n    sns.heatmap(target_df.isna().transpose(),\n                cmap=\"YlGnBu\",\n                cbar_kws={'label': f'Missing Data'})\n    ax.set_title(f'{asset_name}')\n    plt.show()\n","metadata":{"execution":{"iopub.status.busy":"2021-12-02T14:05:02.435295Z","iopub.execute_input":"2021-12-02T14:05:02.435531Z","iopub.status.idle":"2021-12-02T14:09:01.343105Z","shell.execute_reply.started":"2021-12-02T14:05:02.435504Z","shell.execute_reply":"2021-12-02T14:09:01.342197Z"},"trusted":true},"execution_count":null,"outputs":[]}]}