{"cells":[{"metadata":{},"cell_type":"markdown","source":"## Show Us The Data\n\n![](https://storage.googleapis.com/kaggle-competitions/kaggle/25925/logos/header.png)\n\nThis notebook shares several utilities to make it easy to navigate through your data."},{"metadata":{"_uuid":"8f2839f25d086af736a60e9eeb907d3b93b6e0e5","_cell_guid":"b1076dfc-b9ad-4769-8c92-a6c4dae69d19","trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"import numpy as np\nimport pandas as pd\nimport seaborn as sns\nimport matplotlib as mpl\nimport matplotlib.pyplot as plt\nimport plotly.express as px\n\n# Default Setting \nmpl.rcParams['figure.dpi'] = 150\nmpl.rcParams['axes.spines.top'] = False\nmpl.rcParams['axes.spines.right'] = False\n\ntrain = pd.read_csv('../input/coleridgeinitiative-show-us-the-data/train.csv')\n","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Dataset Label Distribution"},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"dataset_label = train['dataset_label'].value_counts()[:20]\nfig = plt.figure(figsize=(15, 7))\n\ngs = fig.add_gridspec(5, 6)\n\nax1 = fig.add_subplot(gs[0,:])\ndataset_label = train['dataset_label'].value_counts()\nax1.bar(dataset_label.index, dataset_label,\n       color=['#244747']*20 + ['#d4dddd']*(len(dataset_label) - 20)\n       )\nax1.set_xticks([])\n\n\nax2 = fig.add_subplot(gs[1:,:])\ndataset_label = train['dataset_label'].value_counts()[:20]\nax2.bar(dataset_label.index, dataset_label,\n        color='#244747'\n       )\nax2.set_xticks(range(len(dataset_label.index)))\nax2.set_xticklabels(dataset_label.index, rotation = 90)\n\n\nfig.text(0.125,0.9,'Dataset Label Distribution', fontsize=20, fontweight='bold', fontfamily='serif')\nplt.show()","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Single Data Loading Utils\n\n**Feel Free To Use**\n\n> Please be sure to leave a reference when using code or taking ideas in my visualizations.\n\n- Convert Json to DataFrame\n- Interactive Table (Comportable to Read)"},{"metadata":{"trusted":true},"cell_type":"code","source":"import plotly.graph_objects as go\nfrom fastcore.all import *\n\ndef read_single_file(df, traintest='train', idx=0):\n    dataset_path = Path('../input/coleridgeinitiative-show-us-the-data')\n    data = pd.DataFrame((dataset_path/traintest/(df['Id'][idx]+'.json')).read_json())\n    fig = go.Figure(data=[go.Table(\n        columnwidth = [100,400],\n        header=dict(values=['Title', 'Article'],\n                    line_color='darkslategray',\n                    fill_color='darkblue',\n                    align='left',  \n                    font=dict(color='white', size=12)\n                   ),\n        cells=dict(values=data.T, \n                   line_color='darkslategray',\n                   fill_color=['lightgray','white'],\n                   align='left'))\n    ])\n\n    dstitle, dslabel = train['dataset_title'][idx], train['dataset_label'][idx]\n    fig.update_layout(title_text=f'{traintest}[{idx}] |{dstitle} | {dslabel} ')\n    fig.update_layout(width=800, height=1000)\n    fig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"read_single_file(train, 'train', 0)","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"read_single_file(train, 'train', 2)","execution_count":null,"outputs":[]},{"metadata":{},"cell_type":"markdown","source":"## Dataset Title > Dataset Label (Treemap)"},{"metadata":{"trusted":true,"_kg_hide-input":true},"cell_type":"code","source":"train['cnt'] = 1\nfig = px.treemap(train, path=['dataset_title', 'dataset_label'], values='cnt',\n                width=1000, height=700, title=\"Dataset Title > Dataset Label\")\nfig.show()","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","execution_count":null,"outputs":[]},{"metadata":{"trusted":true},"cell_type":"code","source":"","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}