Added example of using aliases to Columnar_Data tutorial
{
"cell_type": "code",
"execution_count": null,
- "metadata": {
- "collapsed": true
- },
+ "metadata": {},
"outputs": [],
"source": [
"macro_df = pd.read_csv('http://assets.holoviews.org/macro.csv', '\\t')\n",
+ "HTML(macro_df.head().to_html())"
+ ]
+ },
+ {
+ "cell_type": "markdown",
+ "metadata": {},
+ "source": [
+ "As we can see the data has abbreviated the names of the columns, which is convenient when referring to the variables but is often not whats desired when assigning axis labels, generating widgets or adding titles.\n",
"\n",
- "dimensions = {'unem': 'Unemployment',\n",
- " 'capmob': 'Capital Mobility',\n",
- " 'gdp': 'GDP Growth', \n",
- " 'trade': 'Trade',\n",
- " 'year': 'Year', \n",
- " 'country': 'Country'}\n",
+ "HoloViews dimensions provide a way to alias the variable names so you can continue to refer to the data by their short convenient ``name`` but can also provide a more descriptive ``label``. These can be declared explicitly when creating a Dimension but the most convenient way of specifying aliases is as a tuple where the first item is the ``name`` and the second the ``label``. \n",
"\n",
- "macro_df = macro_df.rename(columns=dimensions)"
+ "Here will declare a list of key dimensions (i.e. the variables the data is indexed by) and a separate list of value dimensions (i.e. the actual observations), which we will use later when declaring a HoloViews object from our data."
+ ]
+ },
+ {
+ "cell_type": "code",
+ "execution_count": null,
+ "metadata": {
+ "collapsed": true
+ },
+ "outputs": [],
+ "source": [
+ "key_dimensions = [('year', 'Year'), ('country', 'Country')]\n",
+ "value_dimensions = [('unem', 'Unemployment'), ('capmob', 'Capital Mobility'),\n",
+ " ('gdp', 'GDP Growth'), ('trade', 'Trade')]"
]
},
{
},
"outputs": [],
"source": [
- "macro = hv.Table(macro_df, kdims=['Year', 'Country'])"
+ "macro = hv.Table(macro_df, kdims=key_dimensions, vdims=value_dimensions)"
]
},
{
