{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {},
"outputs": [],
"source": [
"# Load UCI census and convert to json for sending to the visualization\n",
"import pandas as pd\n",
"features = [\"Age\", \"Workclass\", \"fnlwgt\", \"Education\", \"Education-Num\", \"Marital Status\",\n",
" \"Occupation\", \"Relationship\", \"Race\", \"Sex\", \"Capital Gain\", \"Capital Loss\",\n",
" \"Hours per week\", \"Country\", \"Target\"]\n",
"\n",
"# Load dataframe from external CSV and add header information\n",
"df = pd.read_csv(\"https://archive.ics.uci.edu/ml/machine-learning-databases/adult/adult.test\",\n",
" names=features, # name features for header row\n",
" sep=r'\\s*,\\s*', # separator used in this dataset\n",
" engine='python',\n",
" skiprows=[0], # skip first row without data \n",
" na_values=\"?\") # add ? where data is missing\n",
"\n",
"# set the sprite_size based on the number of records in dataset,\n",
"# larger datasets can crash the browser if the size is too large (>50000)\n",
"sprite_size = 32 if len(df.index)>50000 else 64\n",
"\n",
"jsonstr = df.to_json(orient='records')\n"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {
"scrolled": false
},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" "
],
"text/plain": [
""
]
},
"metadata": {},
"output_type": "display_data"
}
],
"source": [
"\n",
"# Display the Dive visualization for this data\n",
"from IPython.core.display import display, HTML\n",
"\n",
"# Create Facets template \n",
"HTML_TEMPLATE = \"\"\"\n",
" \n",
" \"\"\"\n",
"\n",
"# Load the json dataset and the sprite_size into the template\n",
"html = HTML_TEMPLATE.format(jsonstr=jsonstr, sprite_size=sprite_size)\n",
"\n",
"# Display the template\n",
"display(HTML(html))"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.5.2"
}
},
"nbformat": 4,
"nbformat_minor": 2
}