HEX
Server: Apache/2.4.46 (Win64) OpenSSL/1.1.1j PHP/8.4.25
System: Windows NT DESKTOP-4TAV2RJ 10.0 build 19045 (Windows 10) AMD64
User: fred (0)
PHP: 8.4.25
Disabled: NONE
Upload Files
File: C:/Users/fred/anaconda3/Lib/site-packages/holoviews/examples/reference/elements/plotly/Table.ipynb
{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "<div class=\"contentcontainer med left\" style=\"margin-left: -50px;\">\n",
    "<dl class=\"dl-horizontal\">\n",
    "  <dt>Title</dt> <dd> Table Element</dd>\n",
    "  <dt>Dependencies</dt> <dd>Matplotlib</dd>\n",
    "  <dt>Backends</dt> <dd><a href='../bokeh/Table.ipynb'>Bokeh</a></dd> <dd><a href='../matplotlib/Table.ipynb'>Matplotlib</a></dd> <dd><a href='./Table.ipynb'>Plotly</a></dd>\n",
    "</dl>\n",
    "</div>"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import holoviews as hv\n",
    "hv.extension('plotly')"
   ]
  },
  {
   "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 Datasets](../../../user_guide/07-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": 1
}