{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "
\n", "
Title
Table Element
\n", "
Dependencies
Matplotlib
\n", "
Backends
\n", "
Matplotlib
\n", "
Bokeh
\n", "
Plotly
\n", "
\n", "
" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "import holoviews as hv\n", "hv.extension('matplotlib')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "A table is more general than an [``ItemTable``](./ItemTable.ipynb), as it allows multi-dimensional keys and multidimensional values. Let's say we have the following data:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "gender = ['M','M', 'M','F']\n", "age = [10,16,13,12]\n", "weight = [15,18,16,10]\n", "height = [0.8,0.6,0.7,0.8]" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "We can construct a ``Table`` using a dictionary format (identical in format as that accepted by the [pandas](http://pandas.pydata.org/) ``DataFrame``):" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "hv.Table({'Gender':gender, 'Age':age, 'Weight':weight, 'Height':height},\n", " ['Gender', 'Age'], ['Weight', 'Height'])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Or we can declare the same table by dimension position, with key dimensions followed by value dimensions:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "table = hv.Table((gender, age, weight, height), ['Gender', 'Age'], ['Weight', 'Height'])\n", "table" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Note that you can use the ``select`` method using tables by the key dimensions:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "table.select(Gender='M') + table.select(Gender='M', Age=10)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The ``Table`` is used as a common data structure that may be converted to any other HoloViews data structure via the ``to`` utility available on the object. Here we use this utility to show the weight of the males in our dataset by age:" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "table.select(Gender='M').to.curve(kdims=[\"Age\"], vdims=[\"Weight\"])" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For more extended usage of table conversion see the [Tabular Data](../../../user_guide/08-Tabular_Datasets.ipynb) user guide.\n", "\n", "For full documentation and the available style and plot options, use ``hv.help(hv.Table).``" ] } ], "metadata": { "language_info": { "name": "python", "pygments_lexer": "ipython3" } }, "nbformat": 4, "nbformat_minor": 2 }