{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "971409c2",
   "metadata": {},
   "source": [
    "# How to translate iTable tables to API queries\n",
    "This guide shows how to translate the process of getting data from various iTables searches to using the API. We do this for each of the datasets."
   ]
  },
  {
   "cell_type": "markdown",
   "id": "831c7842",
   "metadata": {},
   "source": [
    "## General info\n",
    "\n",
    "Note that for some scenarios it may take several API queries to generate the data for a single iTables table. Also, in the examples below we often search for a target parameter by a string value in a table. You can always export the table of possibilities to spreadsheet to view the whole thing (e.g., `tbl.to_csv(\"fname.csv\", index=False)`) \n",
    "\n",
    "We first need to figure out what dataset to pull from. Here's roughly how the \"tabs\" on the iTables web page map to the different API datasets:\n",
    "\n",
    "- \"(National Data) GDP & Personal Income\" -> [NIPA, NIUnderlyingDetail]\n",
    "- \"Fixed Assets\" -> FixedAssets\n",
    "- \"GDP by Industry\" -> [GDPbyIndustry, UnderlyingGDPbyIndustry]\n",
    "- \"Input-Output\" -> InputOutput\n",
    "- \"Int'l Transactions, Services, & IIP\" -> [IntlServTrade, ITA, IIP]\n",
    "- \"Direct Investments & MNEs\" -> MNE\n",
    "- \"(Regional Data) GDP & Personal Income\" -> Regional\n",
    "\n",
    "## Other resources\n",
    "While we show one method here, there are some other resources that may be helpful:\n",
    "\n",
    "- `search_metadata()` can be be used for 'FixedAssets', 'NIPA', 'NIUnderlyingDetail'. \n",
    "- NIPA web resources: [Table Title to TableID](https://apps.bea.gov/national/Release/TXT/TablesRegister.txt), [Series Details to Series Code](https://apps.bea.gov/national/Release/TXT/SeriesRegister.txt), [NIPA keywords](https://apps.bea.gov/iTable/iTable.cfm?ReqID=13&step=1)\n",
    "- Fixed Assets web resources: [Table Register](https://apps.bea.gov/national/FixedAssets/Release/TXT/TablesRegister.txt), [Series Register](https://apps.bea.gov/national/FixedAssets/Release/TXT/SeriesRegister.txt),\n",
    "- [Regional API PDF](https://apps.bea.gov/regional/pdf/RegionalApi.pdf) has table mapping \n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0a29f4e6",
   "metadata": {},
   "source": [
    "## Setup"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8713739b",
   "metadata": {},
   "outputs": [],
   "source": [
    "import beaapi\n",
    "\n",
    "import pandas as pd\n",
    "pd.set_option('display.max_colwidth', None)  # show all text in cells"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "8e6404e1",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get key from unversioned file\n",
    "import os\n",
    "from dotenv import load_dotenv\n",
    "load_dotenv()\n",
    "beakey = os.environ.get(\"beakey\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "820b1cd4",
   "metadata": {},
   "source": [
    "### Code utilities\n",
    "We define here a few tools to be use below"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "9194c79b",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Get some basic Meta-data. What are the table names?\n",
    "datasets_info = beaapi.get_data_set_list(beakey)\n",
    "dataset_names = list(datasets_info['DatasetName'])\n",
    "param_infos = {dataset_name: beaapi.get_parameter_list(beakey, dataset_name) for dataset_name in dataset_names}"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a15ea72f",
   "metadata": {},
   "source": [
    "Make a function `get_table_param_from_desc()` to ease getting table IDs from descriptions"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "2da3a6a8",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Tools to help lookup table IDs from table descriptions\n",
    "table_var = {'NIPA':'TableName',\n",
    "    'NIUnderlyingDetail':'TableName',\n",
    "    'MNE':None,\n",
    "    'FixedAssets': 'TableName',\n",
    "    'ITA':None,\n",
    "    'IIP':None,\n",
    "    'InputOutput':\"TableID\",\n",
    "    'IntlServTrade':None,\n",
    "    'GDPbyIndustry':\"TableID\",\n",
    "    'Regional': \"TableName\",\n",
    "    'UnderlyingGDPbyIndustry':\"TableID\"}\n",
    "table_param_desc = {'NIPA':'Description',\n",
    "    'NIUnderlyingDetail':'Description',\n",
    "    'MNE':None,\n",
    "    'FixedAssets': 'Description',\n",
    "    'ITA':None,\n",
    "    'IIP':None,\n",
    "    'InputOutput':\"Desc\",\n",
    "    'IntlServTrade':None,\n",
    "    'GDPbyIndustry':\"Desc\",\n",
    "    'Regional': \"Desc\",\n",
    "    'UnderlyingGDPbyIndustry':\"Desc\"}\n",
    "table_names = {}\n",
    "for dataset_name, table_var_name in table_var.items():\n",
    "    if table_var_name is not None:\n",
    "        table_names[dataset_name] = beaapi.get_parameter_values(beakey, dataset_name, table_var_name)\n",
    "\n",
    "def get_table_param_from_desc(dataset_name, desc):\n",
    "    mask = table_names[dataset_name][table_param_desc[dataset_name]].str.contains(desc)\n",
    "    results = table_names[dataset_name][mask]\n",
    "    table_var_name = table_var[dataset_name]\n",
    "    return table_var_name, results"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "eade9880",
   "metadata": {},
   "source": [
    "## How to build query from iTables"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1596ccae",
   "metadata": {},
   "source": [
    "### National Data - GDP & Personal Income"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c109e34d",
   "metadata": {},
   "source": [
    "#### NIPA (publication category \"GDP and Personal Income\", default)\n",
    "\n",
    "First, let's take as example table the first one on the web page and describe what we do have"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 39,
   "id": "b2feb802",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Example\n",
    "desc = \"Table 1.1.1. Percent Change From Preceding Period in Real Gross Domestic Product\"\n",
    "freq = \"Q\"\n",
    "year = \"2019\" # input as string"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "62eb653b",
   "metadata": {},
   "source": [
    "Then let's see what we need to build the query"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "c4f07046",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ParameterName</th>\n",
       "      <th>ParameterDataType</th>\n",
       "      <th>ParameterDescription</th>\n",
       "      <th>ParameterIsRequiredFlag</th>\n",
       "      <th>ParameterDefaultValue</th>\n",
       "      <th>MultipleAcceptedFlag</th>\n",
       "      <th>AllValue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Frequency</td>\n",
       "      <td>string</td>\n",
       "      <td>A - Annual, Q-Quarterly, M-Monthly</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>ShowMillions</td>\n",
       "      <td>string</td>\n",
       "      <td>A flag indicating that million-dollar data sho...</td>\n",
       "      <td>0</td>\n",
       "      <td>N</td>\n",
       "      <td>0</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>TableID</td>\n",
       "      <td>integer</td>\n",
       "      <td>The standard NIPA table identifier</td>\n",
       "      <td>0</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>0</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>TableName</td>\n",
       "      <td>string</td>\n",
       "      <td>The new NIPA table identifier</td>\n",
       "      <td>0</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>0</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Year</td>\n",
       "      <td>integer</td>\n",
       "      <td>List of year(s) of data to retrieve (X for All)</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td>1</td>\n",
       "      <td>X</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  ParameterName ParameterDataType  \\\n",
       "0     Frequency            string   \n",
       "1  ShowMillions            string   \n",
       "2       TableID           integer   \n",
       "3     TableName            string   \n",
       "4          Year           integer   \n",
       "\n",
       "                                ParameterDescription  ParameterIsRequiredFlag  \\\n",
       "0                 A - Annual, Q-Quarterly, M-Monthly                        1   \n",
       "1  A flag indicating that million-dollar data sho...                        0   \n",
       "2                 The standard NIPA table identifier                        0   \n",
       "3                      The new NIPA table identifier                        0   \n",
       "4    List of year(s) of data to retrieve (X for All)                        1   \n",
       "\n",
       "  ParameterDefaultValue  MultipleAcceptedFlag AllValue  \n",
       "0                                           1           \n",
       "1                     N                     0           \n",
       "2                  <NA>                     0           \n",
       "3                  <NA>                     0           \n",
       "4                                           1        X  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(param_infos[\"NIPA\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "10630d11",
   "metadata": {},
   "source": [
    "Note, we actually need exactly 1 of TableID or TableName. (They transitioned to TableName, but keep TableID around for compatibility.)\n",
    "\n",
    "Next let's find the TableName from the description."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "id": "ffb75e6c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TableName</th>\n",
       "      <th>Description</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>T10101</td>\n",
       "      <td>Table 1.1.1. Percent Change From Preceding Per...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  TableName                                        Description\n",
       "0    T10101  Table 1.1.1. Percent Change From Preceding Per..."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "We'll use that one\n"
     ]
    }
   ],
   "source": [
    "table_param_name, table_param_vals = get_table_param_from_desc(\"NIPA\", desc)\n",
    "display(table_param_vals)\n",
    "print(\"We'll use that one\")\n",
    "table_param_val = table_param_vals.iloc[0,0]\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b3630455",
   "metadata": {},
   "source": [
    "Finally, let's get the data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "8a125105",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TableName</th>\n",
       "      <th>SeriesCode</th>\n",
       "      <th>LineNumber</th>\n",
       "      <th>LineDescription</th>\n",
       "      <th>TimePeriod</th>\n",
       "      <th>METRIC_NAME</th>\n",
       "      <th>CL_UNIT</th>\n",
       "      <th>UNIT_MULT</th>\n",
       "      <th>DataValue</th>\n",
       "      <th>NoteRef</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>T10101</td>\n",
       "      <td>A191RL</td>\n",
       "      <td>1</td>\n",
       "      <td>Gross domestic product</td>\n",
       "      <td>2019Q1</td>\n",
       "      <td>Fisher Quantity Index</td>\n",
       "      <td>Percent change, annual rate</td>\n",
       "      <td>0</td>\n",
       "      <td>2.4</td>\n",
       "      <td>T10101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>T10101</td>\n",
       "      <td>A191RL</td>\n",
       "      <td>1</td>\n",
       "      <td>Gross domestic product</td>\n",
       "      <td>2019Q2</td>\n",
       "      <td>Fisher Quantity Index</td>\n",
       "      <td>Percent change, annual rate</td>\n",
       "      <td>0</td>\n",
       "      <td>3.2</td>\n",
       "      <td>T10101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>T10101</td>\n",
       "      <td>A191RL</td>\n",
       "      <td>1</td>\n",
       "      <td>Gross domestic product</td>\n",
       "      <td>2019Q3</td>\n",
       "      <td>Fisher Quantity Index</td>\n",
       "      <td>Percent change, annual rate</td>\n",
       "      <td>0</td>\n",
       "      <td>2.8</td>\n",
       "      <td>T10101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>T10101</td>\n",
       "      <td>A191RL</td>\n",
       "      <td>1</td>\n",
       "      <td>Gross domestic product</td>\n",
       "      <td>2019Q4</td>\n",
       "      <td>Fisher Quantity Index</td>\n",
       "      <td>Percent change, annual rate</td>\n",
       "      <td>0</td>\n",
       "      <td>1.9</td>\n",
       "      <td>T10101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>T10101</td>\n",
       "      <td>DPCERL</td>\n",
       "      <td>2</td>\n",
       "      <td>Personal consumption expenditures</td>\n",
       "      <td>2019Q1</td>\n",
       "      <td>Fisher Quantity Index</td>\n",
       "      <td>Percent change, annual rate</td>\n",
       "      <td>0</td>\n",
       "      <td>0.6</td>\n",
       "      <td>T10101</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  TableName SeriesCode  LineNumber                    LineDescription  \\\n",
       "0    T10101     A191RL           1             Gross domestic product   \n",
       "1    T10101     A191RL           1             Gross domestic product   \n",
       "2    T10101     A191RL           1             Gross domestic product   \n",
       "3    T10101     A191RL           1             Gross domestic product   \n",
       "4    T10101     DPCERL           2  Personal consumption expenditures   \n",
       "\n",
       "  TimePeriod            METRIC_NAME                      CL_UNIT  UNIT_MULT  \\\n",
       "0     2019Q1  Fisher Quantity Index  Percent change, annual rate          0   \n",
       "1     2019Q2  Fisher Quantity Index  Percent change, annual rate          0   \n",
       "2     2019Q3  Fisher Quantity Index  Percent change, annual rate          0   \n",
       "3     2019Q4  Fisher Quantity Index  Percent change, annual rate          0   \n",
       "4     2019Q1  Fisher Quantity Index  Percent change, annual rate          0   \n",
       "\n",
       "   DataValue NoteRef  \n",
       "0        2.4  T10101  \n",
       "1        3.2  T10101  \n",
       "2        2.8  T10101  \n",
       "3        1.9  T10101  \n",
       "4        0.6  T10101  "
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tbl = beaapi.get_data(beakey, \"NIPA\", TableName=table_param_val, Frequency=freq, Year=year)\n",
    "tbl.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cba8c393",
   "metadata": {},
   "source": [
    "#### NIUnderlyingDetail (Publication Category \"Underlying Details\", non-default)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "94b7e333",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "What parameters are needed\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ParameterName</th>\n",
       "      <th>ParameterDataType</th>\n",
       "      <th>ParameterDescription</th>\n",
       "      <th>ParameterIsRequiredFlag</th>\n",
       "      <th>ParameterDefaultValue</th>\n",
       "      <th>MultipleAcceptedFlag</th>\n",
       "      <th>AllValue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Frequency</td>\n",
       "      <td>string</td>\n",
       "      <td>A - Annual, Q-Quarterly, M-Monthly</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>TableID</td>\n",
       "      <td>integer</td>\n",
       "      <td>The standard NI underlying detail table identi...</td>\n",
       "      <td>0</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>0</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>TableName</td>\n",
       "      <td>string</td>\n",
       "      <td>The new NIPA table identifier</td>\n",
       "      <td>0</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "      <td>0</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Year</td>\n",
       "      <td>integer</td>\n",
       "      <td>List of year(s) of data to retrieve (X for All)</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td>1</td>\n",
       "      <td>X</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  ParameterName ParameterDataType  \\\n",
       "0     Frequency            string   \n",
       "1       TableID           integer   \n",
       "2     TableName            string   \n",
       "3          Year           integer   \n",
       "\n",
       "                                ParameterDescription  ParameterIsRequiredFlag  \\\n",
       "0                 A - Annual, Q-Quarterly, M-Monthly                        1   \n",
       "1  The standard NI underlying detail table identi...                        0   \n",
       "2                      The new NIPA table identifier                        0   \n",
       "3    List of year(s) of data to retrieve (X for All)                        1   \n",
       "\n",
       "  ParameterDefaultValue  MultipleAcceptedFlag AllValue  \n",
       "0                                           1           \n",
       "1                  <NA>                     0           \n",
       "2                  <NA>                     0           \n",
       "3                                           1        X  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Info from iTables\n",
    "desc = \"Table 1AU. Real Manufacturing and Trade Inventories, Seasonally Adjusted, End of Period\" # Note: have to cut off final \"[Chained 1996 dollars, 1967-96, SIC]\" to get it to match\n",
    "freq=\"Q\"\n",
    "year=\"1995\"\n",
    "\n",
    "print(\"What parameters are needed\")\n",
    "display(param_infos[\"NIUnderlyingDetail\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "93ffe259",
   "metadata": {},
   "source": [
    "Get tablename from iTable's table description from web"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "ec92772c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "What TableName matches?\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TableName</th>\n",
       "      <th>Description</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>U001A</td>\n",
       "      <td>Table 1AU. Real Manufacturing and Trade Invent...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  TableName                                        Description\n",
       "0     U001A  Table 1AU. Real Manufacturing and Trade Invent..."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "table_param_name, table_param_vals = get_table_param_from_desc(\"NIUnderlyingDetail\", desc)\n",
    "display(table_param_vals)\n",
    "print(\"That one looks good.\")\n",
    "table_param_val = table_param_vals.iloc[0,0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d34e8dc9",
   "metadata": {},
   "source": [
    "Next, get data."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "35810d43",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TableName</th>\n",
       "      <th>SeriesCode</th>\n",
       "      <th>LineNumber</th>\n",
       "      <th>LineDescription</th>\n",
       "      <th>TimePeriod</th>\n",
       "      <th>METRIC_NAME</th>\n",
       "      <th>CL_UNIT</th>\n",
       "      <th>UNIT_MULT</th>\n",
       "      <th>DataValue</th>\n",
       "      <th>NoteRef</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>U001A</td>\n",
       "      <td>KSTMT</td>\n",
       "      <td>1</td>\n",
       "      <td>Manufacturing and trade</td>\n",
       "      <td>1995Q1</td>\n",
       "      <td>Chained Dollars</td>\n",
       "      <td>Level</td>\n",
       "      <td>6</td>\n",
       "      <td>973434</td>\n",
       "      <td>U001A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>U001A</td>\n",
       "      <td>KSTMT</td>\n",
       "      <td>1</td>\n",
       "      <td>Manufacturing and trade</td>\n",
       "      <td>1995Q2</td>\n",
       "      <td>Chained Dollars</td>\n",
       "      <td>Level</td>\n",
       "      <td>6</td>\n",
       "      <td>984218</td>\n",
       "      <td>U001A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>U001A</td>\n",
       "      <td>KSTMT</td>\n",
       "      <td>1</td>\n",
       "      <td>Manufacturing and trade</td>\n",
       "      <td>1995Q3</td>\n",
       "      <td>Chained Dollars</td>\n",
       "      <td>Level</td>\n",
       "      <td>6</td>\n",
       "      <td>991162</td>\n",
       "      <td>U001A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>U001A</td>\n",
       "      <td>KSTMT</td>\n",
       "      <td>1</td>\n",
       "      <td>Manufacturing and trade</td>\n",
       "      <td>1995Q4</td>\n",
       "      <td>Chained Dollars</td>\n",
       "      <td>Level</td>\n",
       "      <td>6</td>\n",
       "      <td>994259</td>\n",
       "      <td>U001A</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>U001A</td>\n",
       "      <td>KSTM</td>\n",
       "      <td>2</td>\n",
       "      <td>Manufacturing</td>\n",
       "      <td>1995Q1</td>\n",
       "      <td>Chained Dollars</td>\n",
       "      <td>Level</td>\n",
       "      <td>6</td>\n",
       "      <td>410079</td>\n",
       "      <td>U001A</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  TableName SeriesCode  LineNumber          LineDescription TimePeriod  \\\n",
       "0     U001A      KSTMT           1  Manufacturing and trade     1995Q1   \n",
       "1     U001A      KSTMT           1  Manufacturing and trade     1995Q2   \n",
       "2     U001A      KSTMT           1  Manufacturing and trade     1995Q3   \n",
       "3     U001A      KSTMT           1  Manufacturing and trade     1995Q4   \n",
       "4     U001A       KSTM           2            Manufacturing     1995Q1   \n",
       "\n",
       "       METRIC_NAME CL_UNIT  UNIT_MULT  DataValue NoteRef  \n",
       "0  Chained Dollars   Level          6     973434   U001A  \n",
       "1  Chained Dollars   Level          6     984218   U001A  \n",
       "2  Chained Dollars   Level          6     991162   U001A  \n",
       "3  Chained Dollars   Level          6     994259   U001A  \n",
       "4  Chained Dollars   Level          6     410079   U001A  "
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tbl = beaapi.get_data(beakey, \"NIUnderlyingDetail\", TableName=table_param_val, Frequency=freq, Year=year)\n",
    "tbl.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "36220863",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Unsure how to access Publication category \"Additional Tables\"\n",
    "# desc=\"FWPI-1. Fixed-Weighted Price Indexes\"\n",
    "# Both methods fail:\n",
    "#search_result = beaapi.search_metadata(desc, beakey)\n",
    "#display(search_result)\n",
    "#table_param_name, table_param_vals = get_table_param_from_desc(\"NIPA\", desc) #Tried with NIUnderlyingDetail\n",
    "#display(table_param_vals)\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "86a72803",
   "metadata": {},
   "source": [
    "### National Data - Fixed Assets"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d41d074e",
   "metadata": {},
   "source": [
    "#### FixedAssets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "4ea02d7c",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Info from iTable\n",
    "desc = \"Table 1.1. Current-Cost Net Stock of Fixed Assets and Consumer Durable Goods\"\n",
    "year=\"2013\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e092d6dc",
   "metadata": {},
   "source": [
    "First, what parameters are needed?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "8c94459d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ParameterName</th>\n",
       "      <th>ParameterDataType</th>\n",
       "      <th>ParameterDescription</th>\n",
       "      <th>ParameterIsRequiredFlag</th>\n",
       "      <th>ParameterDefaultValue</th>\n",
       "      <th>MultipleAcceptedFlag</th>\n",
       "      <th>AllValue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>TableName</td>\n",
       "      <td>string</td>\n",
       "      <td>The new Fixed Assets identifier</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td>0</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Year</td>\n",
       "      <td>integer</td>\n",
       "      <td>List of year(s) of data to retrieve (X for All)</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td>1</td>\n",
       "      <td>X</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  ParameterName ParameterDataType  \\\n",
       "0     TableName            string   \n",
       "1          Year           integer   \n",
       "\n",
       "                              ParameterDescription  ParameterIsRequiredFlag  \\\n",
       "0                  The new Fixed Assets identifier                        1   \n",
       "1  List of year(s) of data to retrieve (X for All)                        1   \n",
       "\n",
       "  ParameterDefaultValue  MultipleAcceptedFlag AllValue  \n",
       "0                                           0           \n",
       "1                                           1        X  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(param_infos[\"FixedAssets\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6876eb6a",
   "metadata": {},
   "source": [
    "Get tablename from iTable's table description from web"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "a5e22b22",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TableName</th>\n",
       "      <th>Description</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>FAAt101</td>\n",
       "      <td>Table 1.1. Current-Cost Net Stock of Fixed Ass...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  TableName                                        Description\n",
       "0   FAAt101  Table 1.1. Current-Cost Net Stock of Fixed Ass..."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "table_param_name, table_param_vals = get_table_param_from_desc(\"FixedAssets\", desc)\n",
    "display(table_param_vals)\n",
    "print(\"That one looks good\")\n",
    "table_param_val = table_param_vals.iloc[0,0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5068a7e8",
   "metadata": {},
   "source": [
    "Get data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "03b3ec6e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TableName</th>\n",
       "      <th>SeriesCode</th>\n",
       "      <th>LineNumber</th>\n",
       "      <th>LineDescription</th>\n",
       "      <th>TimePeriod</th>\n",
       "      <th>METRIC_NAME</th>\n",
       "      <th>CL_UNIT</th>\n",
       "      <th>UNIT_MULT</th>\n",
       "      <th>DataValue</th>\n",
       "      <th>NoteRef</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>FAAt101</td>\n",
       "      <td>k1wtotl1es00</td>\n",
       "      <td>1</td>\n",
       "      <td>Fixed assets and consumer durable goods</td>\n",
       "      <td>2013</td>\n",
       "      <td>Current Dollars</td>\n",
       "      <td>Level</td>\n",
       "      <td>9</td>\n",
       "      <td>56290.3</td>\n",
       "      <td>FAAt101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>FAAt101</td>\n",
       "      <td>k1ttotl1es00</td>\n",
       "      <td>2</td>\n",
       "      <td>Fixed assets</td>\n",
       "      <td>2013</td>\n",
       "      <td>Current Dollars</td>\n",
       "      <td>Level</td>\n",
       "      <td>9</td>\n",
       "      <td>51510.7</td>\n",
       "      <td>FAAt101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>FAAt101</td>\n",
       "      <td>k1ptotl1es00</td>\n",
       "      <td>3</td>\n",
       "      <td>Private</td>\n",
       "      <td>2013</td>\n",
       "      <td>Current Dollars</td>\n",
       "      <td>Level</td>\n",
       "      <td>9</td>\n",
       "      <td>38567.6</td>\n",
       "      <td>FAAt101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>FAAt101</td>\n",
       "      <td>k1ntotl1es00</td>\n",
       "      <td>4</td>\n",
       "      <td>Nonresidential</td>\n",
       "      <td>2013</td>\n",
       "      <td>Current Dollars</td>\n",
       "      <td>Level</td>\n",
       "      <td>9</td>\n",
       "      <td>21073.3</td>\n",
       "      <td>FAAt101</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>FAAt101</td>\n",
       "      <td>k1ntotl1eq00</td>\n",
       "      <td>5</td>\n",
       "      <td>Equipment</td>\n",
       "      <td>2013</td>\n",
       "      <td>Current Dollars</td>\n",
       "      <td>Level</td>\n",
       "      <td>9</td>\n",
       "      <td>5897.2</td>\n",
       "      <td>FAAt101</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  TableName    SeriesCode  LineNumber  \\\n",
       "0   FAAt101  k1wtotl1es00           1   \n",
       "1   FAAt101  k1ttotl1es00           2   \n",
       "2   FAAt101  k1ptotl1es00           3   \n",
       "3   FAAt101  k1ntotl1es00           4   \n",
       "4   FAAt101  k1ntotl1eq00           5   \n",
       "\n",
       "                           LineDescription TimePeriod      METRIC_NAME  \\\n",
       "0  Fixed assets and consumer durable goods       2013  Current Dollars   \n",
       "1                             Fixed assets       2013  Current Dollars   \n",
       "2                                  Private       2013  Current Dollars   \n",
       "3                           Nonresidential       2013  Current Dollars   \n",
       "4                                Equipment       2013  Current Dollars   \n",
       "\n",
       "  CL_UNIT  UNIT_MULT  DataValue  NoteRef  \n",
       "0   Level          9    56290.3  FAAt101  \n",
       "1   Level          9    51510.7  FAAt101  \n",
       "2   Level          9    38567.6  FAAt101  \n",
       "3   Level          9    21073.3  FAAt101  \n",
       "4   Level          9     5897.2  FAAt101  "
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tbl = beaapi.get_data(beakey, \"FixedAssets\", TableName=table_param_val, Year=year)\n",
    "tbl.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d47d36fa",
   "metadata": {},
   "source": [
    "### Industry Data"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "65a693aa",
   "metadata": {},
   "source": [
    "#### GDPbyIndustry (Publication category \"GDP-by-Industry\", a default)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "841d6a88",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Info from iTable\n",
    "desc = \"Value Added by Industry\"\n",
    "year=\"2019\"\n",
    "freq=\"Q\"\n",
    "industries = \"ALL\" # from iTable"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2746d0f1",
   "metadata": {},
   "source": [
    "First, what parameters are needed?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "id": "8f271f1e",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ParameterName</th>\n",
       "      <th>ParameterDataType</th>\n",
       "      <th>ParameterDescription</th>\n",
       "      <th>ParameterIsRequiredFlag</th>\n",
       "      <th>ParameterDefaultValue</th>\n",
       "      <th>MultipleAcceptedFlag</th>\n",
       "      <th>AllValue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Frequency</td>\n",
       "      <td>string</td>\n",
       "      <td>A - Annual, Q-Quarterly</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Industry</td>\n",
       "      <td>string</td>\n",
       "      <td>List of industries to retrieve (ALL for All)</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>TableID</td>\n",
       "      <td>integer</td>\n",
       "      <td>The unique GDP by Industry table identifier (A...</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Year</td>\n",
       "      <td>integer</td>\n",
       "      <td>List of year(s) of data to retrieve (ALL for All)</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  ParameterName ParameterDataType  \\\n",
       "0     Frequency            string   \n",
       "1      Industry            string   \n",
       "2       TableID           integer   \n",
       "3          Year           integer   \n",
       "\n",
       "                                ParameterDescription  ParameterIsRequiredFlag  \\\n",
       "0                            A - Annual, Q-Quarterly                        1   \n",
       "1       List of industries to retrieve (ALL for All)                        1   \n",
       "2  The unique GDP by Industry table identifier (A...                        1   \n",
       "3  List of year(s) of data to retrieve (ALL for All)                        1   \n",
       "\n",
       "  ParameterDefaultValue  MultipleAcceptedFlag AllValue  \n",
       "0                                           1      ALL  \n",
       "1                                           1      ALL  \n",
       "2                                           1      ALL  \n",
       "3                                           1      ALL  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(param_infos[\"GDPbyIndustry\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "80d650ff",
   "metadata": {},
   "source": [
    "Get tablename"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "ca33ed8b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "What TableName matches?\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Key</th>\n",
       "      <th>Desc</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Value Added by Industry (A) (Q)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>6</td>\n",
       "      <td>Components of Value Added by Industry (A)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>7</td>\n",
       "      <td>Components of Value Added by Industry as a Per...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>8</td>\n",
       "      <td>Chain-Type Quantity Indexes for Value Added by...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>9</td>\n",
       "      <td>Percent Changes in Chain-Type Quantity Indexes...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>10</td>\n",
       "      <td>Real Value Added by Industry (A) (Q)</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>11</td>\n",
       "      <td>Chain-Type Price Indexes for Value Added by In...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>12</td>\n",
       "      <td>Percent Changes in Chain-Type Price Indexes fo...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Key                                               Desc\n",
       "0   1                    Value Added by Industry (A) (Q)\n",
       "2   6          Components of Value Added by Industry (A)\n",
       "3   7  Components of Value Added by Industry as a Per...\n",
       "4   8  Chain-Type Quantity Indexes for Value Added by...\n",
       "5   9  Percent Changes in Chain-Type Quantity Indexes...\n",
       "6  10               Real Value Added by Industry (A) (Q)\n",
       "7  11  Chain-Type Price Indexes for Value Added by In...\n",
       "8  12  Percent Changes in Chain-Type Price Indexes fo..."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "table_param_name, table_param_vals = get_table_param_from_desc(\"GDPbyIndustry\", desc)\n",
    "display(table_param_vals)\n",
    "print(\"That first one looks right.\")\n",
    "table_param_val = table_param_vals.iloc[0,0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5b8c8371",
   "metadata": {},
   "source": [
    "Get data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 31,
   "id": "9ed4c1ee",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TableID</th>\n",
       "      <th>Frequency</th>\n",
       "      <th>Year</th>\n",
       "      <th>Quarter</th>\n",
       "      <th>Industry</th>\n",
       "      <th>IndustrYDescription</th>\n",
       "      <th>DataValue</th>\n",
       "      <th>NoteRef</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Q</td>\n",
       "      <td>2019</td>\n",
       "      <td>I</td>\n",
       "      <td>11</td>\n",
       "      <td>Agriculture, forestry, fishing, and hunting</td>\n",
       "      <td>159.7</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1</td>\n",
       "      <td>Q</td>\n",
       "      <td>2019</td>\n",
       "      <td>I</td>\n",
       "      <td>111CA</td>\n",
       "      <td>Farms</td>\n",
       "      <td>120.9</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1</td>\n",
       "      <td>Q</td>\n",
       "      <td>2019</td>\n",
       "      <td>I</td>\n",
       "      <td>113FF</td>\n",
       "      <td>Forestry, fishing, and related activities</td>\n",
       "      <td>38.8</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>Q</td>\n",
       "      <td>2019</td>\n",
       "      <td>I</td>\n",
       "      <td>21</td>\n",
       "      <td>Mining</td>\n",
       "      <td>302.1</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>Q</td>\n",
       "      <td>2019</td>\n",
       "      <td>I</td>\n",
       "      <td>211</td>\n",
       "      <td>Oil and gas extraction</td>\n",
       "      <td>185.6</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   TableID Frequency  Year Quarter Industry  \\\n",
       "0        1         Q  2019       I       11   \n",
       "1        1         Q  2019       I    111CA   \n",
       "2        1         Q  2019       I    113FF   \n",
       "3        1         Q  2019       I       21   \n",
       "4        1         Q  2019       I      211   \n",
       "\n",
       "                           IndustrYDescription  DataValue NoteRef  \n",
       "0  Agriculture, forestry, fishing, and hunting      159.7       1  \n",
       "1                                        Farms      120.9       1  \n",
       "2    Forestry, fishing, and related activities       38.8       1  \n",
       "3                                       Mining      302.1       1  \n",
       "4                       Oil and gas extraction      185.6       1  "
      ]
     },
     "execution_count": 31,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tbl = beaapi.get_data(beakey, \"GDPbyIndustry\", TableID=table_param_val, Year=year, Frequency=freq, Industry=industries)\n",
    "tbl.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3e177570",
   "metadata": {},
   "source": [
    "#### UnderlyingGDPbyIndustry  (Publication category \"Underlying\", non-default)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 35,
   "id": "2c843b02",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Info from iTable\n",
    "desc = \"U.Value Added by Industry\"\n",
    "year=\"2013\"\n",
    "freq=\"A\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "671bd322",
   "metadata": {},
   "source": [
    "What parameters are needed?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "d0fdcbb9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ParameterName</th>\n",
       "      <th>ParameterDataType</th>\n",
       "      <th>ParameterDescription</th>\n",
       "      <th>ParameterIsRequiredFlag</th>\n",
       "      <th>ParameterDefaultValue</th>\n",
       "      <th>MultipleAcceptedFlag</th>\n",
       "      <th>AllValue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Frequency</td>\n",
       "      <td>string</td>\n",
       "      <td>Q-Quarterly</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Industry</td>\n",
       "      <td>string</td>\n",
       "      <td>List of industries to retrieve (ALL for All)</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>TableID</td>\n",
       "      <td>integer</td>\n",
       "      <td>The unique Underlying GDP by Industry table id...</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Year</td>\n",
       "      <td>integer</td>\n",
       "      <td>List of year(s) of data to retrieve (ALL for All)</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  ParameterName ParameterDataType  \\\n",
       "0     Frequency            string   \n",
       "1      Industry            string   \n",
       "2       TableID           integer   \n",
       "3          Year           integer   \n",
       "\n",
       "                                ParameterDescription  ParameterIsRequiredFlag  \\\n",
       "0                                        Q-Quarterly                        1   \n",
       "1       List of industries to retrieve (ALL for All)                        1   \n",
       "2  The unique Underlying GDP by Industry table id...                        1   \n",
       "3  List of year(s) of data to retrieve (ALL for All)                        1   \n",
       "\n",
       "  ParameterDefaultValue  MultipleAcceptedFlag AllValue  \n",
       "0                                           1      ALL  \n",
       "1                                           1      ALL  \n",
       "2                                           1      ALL  \n",
       "3                                           1      ALL  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "display(param_infos[\"UnderlyingGDPbyIndustry\"])\n",
    "industries = \"ALL\" # from iTable"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a89d6e02",
   "metadata": {},
   "source": [
    "Get tablename"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 37,
   "id": "0961c284",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "What TableName matches?\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Key</th>\n",
       "      <th>Desc</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>210</td>\n",
       "      <td>U.Value Added by Industry (A)</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Key                           Desc\n",
       "0  210  U.Value Added by Industry (A)"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "First one\n"
     ]
    }
   ],
   "source": [
    "table_param_name, table_param_vals = get_table_param_from_desc(\"UnderlyingGDPbyIndustry\", desc)\n",
    "print(\"What TableName matches?\")\n",
    "display(table_param_vals)\n",
    "table_param_val = table_param_vals.iloc[0,0]\n",
    "print(\"First one\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "bd84e98a",
   "metadata": {},
   "source": [
    "Get data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "9bf09147",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TableID</th>\n",
       "      <th>Frequency</th>\n",
       "      <th>Year</th>\n",
       "      <th>Industry</th>\n",
       "      <th>IndustrYDescription</th>\n",
       "      <th>DataValue</th>\n",
       "      <th>NoteRef</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>210</td>\n",
       "      <td>A</td>\n",
       "      <td>2013</td>\n",
       "      <td>11</td>\n",
       "      <td>Agriculture, forestry, fishing, and hunting</td>\n",
       "      <td>214.3</td>\n",
       "      <td>210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>210</td>\n",
       "      <td>A</td>\n",
       "      <td>2013</td>\n",
       "      <td>111</td>\n",
       "      <td>Crop production</td>\n",
       "      <td>111.7</td>\n",
       "      <td>210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>210</td>\n",
       "      <td>A</td>\n",
       "      <td>2013</td>\n",
       "      <td>111CA</td>\n",
       "      <td>Farms</td>\n",
       "      <td>183.3</td>\n",
       "      <td>210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>210</td>\n",
       "      <td>A</td>\n",
       "      <td>2013</td>\n",
       "      <td>112</td>\n",
       "      <td>Animal production and aquaculture</td>\n",
       "      <td>71.5</td>\n",
       "      <td>210</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>210</td>\n",
       "      <td>A</td>\n",
       "      <td>2013</td>\n",
       "      <td>113FF</td>\n",
       "      <td>Forestry, fishing, and related activities</td>\n",
       "      <td>31.0</td>\n",
       "      <td>210</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   TableID Frequency  Year Industry  \\\n",
       "0      210         A  2013       11   \n",
       "1      210         A  2013      111   \n",
       "2      210         A  2013    111CA   \n",
       "3      210         A  2013      112   \n",
       "4      210         A  2013    113FF   \n",
       "\n",
       "                           IndustrYDescription  DataValue NoteRef  \n",
       "0  Agriculture, forestry, fishing, and hunting      214.3     210  \n",
       "1                              Crop production      111.7     210  \n",
       "2                                        Farms      183.3     210  \n",
       "3            Animal production and aquaculture       71.5     210  \n",
       "4    Forestry, fishing, and related activities       31.0     210  "
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tbl = beaapi.get_data(beakey, \"UnderlyingGDPbyIndustry\", TableID=table_param_val, Year=year, Frequency=freq, Industry=industries)\n",
    "tbl.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7270d7c4",
   "metadata": {},
   "source": [
    "#### InputOutput  (Publication category \"Input-Output\", a default)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 43,
   "id": "3681d98f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "What parameters are needed\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ParameterName</th>\n",
       "      <th>ParameterDataType</th>\n",
       "      <th>ParameterDescription</th>\n",
       "      <th>ParameterIsRequiredFlag</th>\n",
       "      <th>ParameterDefaultValue</th>\n",
       "      <th>MultipleAcceptedFlag</th>\n",
       "      <th>AllValue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>TableID</td>\n",
       "      <td>integer</td>\n",
       "      <td>The unique Input-Output table identifier</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Year</td>\n",
       "      <td>integer</td>\n",
       "      <td>List of year(s) of data to retrieve (ALL for All)</td>\n",
       "      <td>1</td>\n",
       "      <td></td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  ParameterName ParameterDataType  \\\n",
       "0       TableID           integer   \n",
       "1          Year           integer   \n",
       "\n",
       "                                ParameterDescription  ParameterIsRequiredFlag  \\\n",
       "0           The unique Input-Output table identifier                        1   \n",
       "1  List of year(s) of data to retrieve (ALL for All)                        1   \n",
       "\n",
       "  ParameterDefaultValue  MultipleAcceptedFlag AllValue  \n",
       "0                                           1           \n",
       "1                                           1      ALL  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Info from iTable\n",
    "desc = \"The Use of Commodities by Industries - Sector\"\n",
    "year=\"2020\"\n",
    "\n",
    "print(\"What parameters are needed\")\n",
    "display(param_infos[\"InputOutput\"])\n",
    "#industries = \"ALL\" # from iTable"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c5e7e031",
   "metadata": {},
   "source": [
    "Get tablename"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "1cbb0be8",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "What TableName matches?\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Key</th>\n",
       "      <th>Desc</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>258</td>\n",
       "      <td>The Use of Commodities by Industries - Sector</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   Key                                           Desc\n",
       "9  258  The Use of Commodities by Industries - Sector"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "That first one looks good\n"
     ]
    }
   ],
   "source": [
    "table_param_name, table_param_vals = get_table_param_from_desc(\"InputOutput\", desc)\n",
    "print(\"What TableName matches?\")\n",
    "display(table_param_vals)\n",
    "print(\"That first one looks good\")\n",
    "table_param_val = table_param_vals.iloc[0,0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "63bf93f6",
   "metadata": {},
   "source": [
    "Get data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "id": "27544d1f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TableID</th>\n",
       "      <th>Year</th>\n",
       "      <th>RowCode</th>\n",
       "      <th>RowDescr</th>\n",
       "      <th>RowType</th>\n",
       "      <th>ColCode</th>\n",
       "      <th>ColDescr</th>\n",
       "      <th>ColType</th>\n",
       "      <th>DataValue</th>\n",
       "      <th>NoteRef</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>258</td>\n",
       "      <td>2020</td>\n",
       "      <td>11</td>\n",
       "      <td>Agriculture, forestry, fishing, and hunting</td>\n",
       "      <td>Commodity</td>\n",
       "      <td>11</td>\n",
       "      <td>Agriculture, forestry, fishing, and hunting</td>\n",
       "      <td>Industry</td>\n",
       "      <td>106419</td>\n",
       "      <td>258</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>258</td>\n",
       "      <td>2020</td>\n",
       "      <td>11</td>\n",
       "      <td>Agriculture, forestry, fishing, and hunting</td>\n",
       "      <td>Commodity</td>\n",
       "      <td>T001</td>\n",
       "      <td>Total Intermediate</td>\n",
       "      <td>Industry</td>\n",
       "      <td>446013</td>\n",
       "      <td>258</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>258</td>\n",
       "      <td>2020</td>\n",
       "      <td>11</td>\n",
       "      <td>Agriculture, forestry, fishing, and hunting</td>\n",
       "      <td>Commodity</td>\n",
       "      <td>31G</td>\n",
       "      <td>Manufacturing</td>\n",
       "      <td>Industry</td>\n",
       "      <td>309395</td>\n",
       "      <td>258</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>258</td>\n",
       "      <td>2020</td>\n",
       "      <td>11</td>\n",
       "      <td>Agriculture, forestry, fishing, and hunting</td>\n",
       "      <td>Commodity</td>\n",
       "      <td>7</td>\n",
       "      <td>Arts, entertainment, recreation, accommodation...</td>\n",
       "      <td>Industry</td>\n",
       "      <td>8556</td>\n",
       "      <td>258</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>258</td>\n",
       "      <td>2020</td>\n",
       "      <td>11</td>\n",
       "      <td>Agriculture, forestry, fishing, and hunting</td>\n",
       "      <td>Commodity</td>\n",
       "      <td>21</td>\n",
       "      <td>Mining</td>\n",
       "      <td>Industry</td>\n",
       "      <td>168</td>\n",
       "      <td>258</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   TableID  Year RowCode                                     RowDescr  \\\n",
       "0      258  2020      11  Agriculture, forestry, fishing, and hunting   \n",
       "1      258  2020      11  Agriculture, forestry, fishing, and hunting   \n",
       "2      258  2020      11  Agriculture, forestry, fishing, and hunting   \n",
       "3      258  2020      11  Agriculture, forestry, fishing, and hunting   \n",
       "4      258  2020      11  Agriculture, forestry, fishing, and hunting   \n",
       "\n",
       "     RowType ColCode                                           ColDescr  \\\n",
       "0  Commodity      11        Agriculture, forestry, fishing, and hunting   \n",
       "1  Commodity    T001                                 Total Intermediate   \n",
       "2  Commodity     31G                                      Manufacturing   \n",
       "3  Commodity       7  Arts, entertainment, recreation, accommodation...   \n",
       "4  Commodity      21                                             Mining   \n",
       "\n",
       "    ColType  DataValue NoteRef  \n",
       "0  Industry     106419     258  \n",
       "1  Industry     446013     258  \n",
       "2  Industry     309395     258  \n",
       "3  Industry       8556     258  \n",
       "4  Industry        168     258  "
      ]
     },
     "execution_count": 45,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tbl = beaapi.get_data(beakey, \"InputOutput\", TableID=table_param_val, Year=year)\n",
    "tbl.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "a3392edb",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# Unsure how to access Publication category \"Make Use Framework\"\n",
    "# desc=\"The Use of Commodities by Industries, After Redefinitions\"\n",
    "# Both methods fail:\n",
    "#search_result = beaapi.search_metadata(desc, beakey)\n",
    "#display(search_result)\n",
    "#table_param_name, table_param_vals = get_table_param_from_desc(\"UnderlyingGDPbyIndustry\", desc) # Tried also with InputOutput, GDPbyIndustry\n",
    "#display(table_param_vals)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b3b3dbc6",
   "metadata": {},
   "source": [
    "### Int'l Transactions, Services, IIP"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "30535e5a",
   "metadata": {},
   "source": [
    "#### ITA\n",
    "\n",
    "The different tables are associated with different sets of lines (indicators). So some tables aren't easy to reconstruct exactly.\n",
    "\n",
    "Note: (in PDF but API error msg confusing) you can't get all indicators using \"AllCountries\" (agg'd over countries), even though that would seem easy (and is something like like table 1.1).\n",
    "\n",
    "Basically you have to look through `beaapi.get_parameter_values(beakey, \"ITA\", \"Indicator\")`\n",
    "\n",
    "Note also that the following indicators don't report global sum, so ask for all countries individually: 'ExpGdsAutoEngAndEngParts', 'ExpGdsOthAutoPartsAndAcc', 'ExpGdsPassCars', 'ExpGdsTrucksBusesSpecPurpVeh',  'ImpGdsAutoEngAndEngParts', 'ImpGdsOthAutoPartsAndAcc',  'ImpGdsPassCars', 'ImpGdsTrucksBusesSpecPurpVeh'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "id": "2a533b87",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "What parameters are needed\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ParameterName</th>\n",
       "      <th>ParameterDataType</th>\n",
       "      <th>ParameterDescription</th>\n",
       "      <th>ParameterIsRequiredFlag</th>\n",
       "      <th>ParameterDefaultValue</th>\n",
       "      <th>MultipleAcceptedFlag</th>\n",
       "      <th>AllValue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Indicator</td>\n",
       "      <td>string</td>\n",
       "      <td>The indicator code for the type of transaction...</td>\n",
       "      <td>0</td>\n",
       "      <td>ALL</td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>AreaOrCountry</td>\n",
       "      <td>string</td>\n",
       "      <td>The area or country requested</td>\n",
       "      <td>0</td>\n",
       "      <td>AllCountries</td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Frequency</td>\n",
       "      <td>string</td>\n",
       "      <td>A - Annual, QSA - Quarterly seasonally adjuste...</td>\n",
       "      <td>0</td>\n",
       "      <td>ALL</td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Year</td>\n",
       "      <td>string</td>\n",
       "      <td>Year requested</td>\n",
       "      <td>0</td>\n",
       "      <td>ALL</td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   ParameterName ParameterDataType  \\\n",
       "0      Indicator            string   \n",
       "1  AreaOrCountry            string   \n",
       "2      Frequency            string   \n",
       "3           Year            string   \n",
       "\n",
       "                                ParameterDescription  ParameterIsRequiredFlag  \\\n",
       "0  The indicator code for the type of transaction...                        0   \n",
       "1                      The area or country requested                        0   \n",
       "2  A - Annual, QSA - Quarterly seasonally adjuste...                        0   \n",
       "3                                     Year requested                        0   \n",
       "\n",
       "  ParameterDefaultValue  MultipleAcceptedFlag AllValue  \n",
       "0                   ALL                     1      ALL  \n",
       "1          AllCountries                     1      ALL  \n",
       "2                   ALL                     1      ALL  \n",
       "3                   ALL                     1      ALL  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Roughly one line from \"Table 1.2. U.S. International Transactions, Expanded Detail\"\n",
    "year=\"2020\"\n",
    "freq=\"QSA\"\n",
    "cntry=\"AllCountries\"\n",
    "desc = \"Balance on goods\"\n",
    "\n",
    "print(\"What parameters are needed\")\n",
    "display(param_infos[\"ITA\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c0a4eec0",
   "metadata": {},
   "source": [
    "Get indicator (or get a single country)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "id": "4ba610f3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Key</th>\n",
       "      <th>Desc</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>BalGds</td>\n",
       "      <td>Balance on goods</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>BalGdsServ</td>\n",
       "      <td>Balance on goods and services</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "          Key                           Desc\n",
       "2      BalGds               Balance on goods\n",
       "3  BalGdsServ  Balance on goods and services"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Take the first one\n"
     ]
    }
   ],
   "source": [
    "# areas_ITA = beaapi.get_parameter_values(beakey, 'ITA', 'AreaOrCountry')\n",
    "ita_indicatorsID = beaapi.get_parameter_values(beakey, 'ITA', 'Indicator')\n",
    "\n",
    "ind_result = ita_indicatorsID[ita_indicatorsID[\"Desc\"].str.contains(desc)]\n",
    "display(ind_result)\n",
    "print(\"Take the first one\")\n",
    "indicator = \"BalGds\""
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b754ce93",
   "metadata": {},
   "source": [
    "Get data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "id": "7f28eb96",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Indicator</th>\n",
       "      <th>AreaOrCountry</th>\n",
       "      <th>Frequency</th>\n",
       "      <th>Year</th>\n",
       "      <th>TimeSeriesId</th>\n",
       "      <th>TimeSeriesDescription</th>\n",
       "      <th>TimePeriod</th>\n",
       "      <th>CL_UNIT</th>\n",
       "      <th>UNIT_MULT</th>\n",
       "      <th>DataValue</th>\n",
       "      <th>NoteRef</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>BalGds</td>\n",
       "      <td>AllCountries</td>\n",
       "      <td>QSA</td>\n",
       "      <td>2020</td>\n",
       "      <td>TSI_ItaBalGds_QSA</td>\n",
       "      <td>Balance on goods; quarterly seasonally adjusted</td>\n",
       "      <td>2020Q3</td>\n",
       "      <td>USD</td>\n",
       "      <td>6</td>\n",
       "      <td>-245370</td>\n",
       "      <td>Q</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>BalGds</td>\n",
       "      <td>AllCountries</td>\n",
       "      <td>QSA</td>\n",
       "      <td>2020</td>\n",
       "      <td>TSI_ItaBalGds_QSA</td>\n",
       "      <td>Balance on goods; quarterly seasonally adjusted</td>\n",
       "      <td>2020Q4</td>\n",
       "      <td>USD</td>\n",
       "      <td>6</td>\n",
       "      <td>-253125</td>\n",
       "      <td>Q</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  Indicator AreaOrCountry Frequency  Year       TimeSeriesId  \\\n",
       "0    BalGds  AllCountries       QSA  2020  TSI_ItaBalGds_QSA   \n",
       "1    BalGds  AllCountries       QSA  2020  TSI_ItaBalGds_QSA   \n",
       "\n",
       "                             TimeSeriesDescription TimePeriod CL_UNIT  \\\n",
       "0  Balance on goods; quarterly seasonally adjusted     2020Q3     USD   \n",
       "1  Balance on goods; quarterly seasonally adjusted     2020Q4     USD   \n",
       "\n",
       "  UNIT_MULT  DataValue NoteRef  \n",
       "0         6    -245370       Q  \n",
       "1         6    -253125       Q  "
      ]
     },
     "execution_count": 52,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tbl = beaapi.get_data(beakey, \"ITA\", Year=year, AreaOrCountry=cntry, Frequency=freq, Indicator=indicator)\n",
    "tbl.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "53f8ab84",
   "metadata": {},
   "source": [
    "#### IntlServTrade\n",
    "\n",
    "Similar issue about different iTables tables being different sets or broken out by country in different ways. Basically have to look at TypeOfService values to line up with tables. Though in this case we can get all types of service of \"AllCountries\" (agg'd over countries)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 56,
   "id": "761e3963",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "What parameters are needed\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ParameterName</th>\n",
       "      <th>ParameterDataType</th>\n",
       "      <th>ParameterDescription</th>\n",
       "      <th>ParameterIsRequiredFlag</th>\n",
       "      <th>ParameterDefaultValue</th>\n",
       "      <th>MultipleAcceptedFlag</th>\n",
       "      <th>AllValue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>TypeOfService</td>\n",
       "      <td>string</td>\n",
       "      <td>The type of service requested</td>\n",
       "      <td>0</td>\n",
       "      <td>ALL</td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>TradeDirection</td>\n",
       "      <td>string</td>\n",
       "      <td>The trade direction requested</td>\n",
       "      <td>0</td>\n",
       "      <td>ALL</td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Affiliation</td>\n",
       "      <td>string</td>\n",
       "      <td>The affiliation requested</td>\n",
       "      <td>0</td>\n",
       "      <td>ALL</td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>AreaOrCountry</td>\n",
       "      <td>string</td>\n",
       "      <td>The area or country requested</td>\n",
       "      <td>0</td>\n",
       "      <td>AllCountries</td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Year</td>\n",
       "      <td>string</td>\n",
       "      <td>The year requested</td>\n",
       "      <td>0</td>\n",
       "      <td>ALL</td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    ParameterName ParameterDataType           ParameterDescription  \\\n",
       "0   TypeOfService            string  The type of service requested   \n",
       "1  TradeDirection            string  The trade direction requested   \n",
       "2     Affiliation            string      The affiliation requested   \n",
       "3   AreaOrCountry            string  The area or country requested   \n",
       "4            Year            string             The year requested   \n",
       "\n",
       "   ParameterIsRequiredFlag ParameterDefaultValue  MultipleAcceptedFlag  \\\n",
       "0                        0                   ALL                     1   \n",
       "1                        0                   ALL                     1   \n",
       "2                        0                   ALL                     1   \n",
       "3                        0          AllCountries                     1   \n",
       "4                        0                   ALL                     1   \n",
       "\n",
       "  AllValue  \n",
       "0      ALL  \n",
       "1      ALL  \n",
       "2      ALL  \n",
       "3      ALL  \n",
       "4      ALL  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "type_desc = \"Sea transport\"\n",
    "\n",
    "print(\"What parameters are needed\")\n",
    "display(param_infos[\"IntlServTrade\"])\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1dff60cd",
   "metadata": {},
   "source": [
    "Get type"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "id": "574b1e1b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Key</th>\n",
       "      <th>Desc</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>104</th>\n",
       "      <td>TransportSea</td>\n",
       "      <td>Sea transport services</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              Key                    Desc\n",
       "104  TransportSea  Sea transport services"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# cntr_IST = beaapi.get_parameter_values(beakey, 'IntlServTrade', 'AreaOrCountry')\n",
    "ist_Type = beaapi.get_parameter_values(beakey, 'IntlServTrade', 'TypeOfService')\n",
    "type_result = ist_Type[ist_Type[\"Desc\"].str.contains(type_desc)]\n",
    "display(type_result)\n",
    "type_of_service = type_result.iloc[0,0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8381effa",
   "metadata": {},
   "source": [
    "Get data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 59,
   "id": "a4c65c5b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TypeOfService</th>\n",
       "      <th>TradeDirection</th>\n",
       "      <th>Affiliation</th>\n",
       "      <th>AreaOrCountry</th>\n",
       "      <th>Year</th>\n",
       "      <th>TimeSeriesId</th>\n",
       "      <th>TimeSeriesDescription</th>\n",
       "      <th>TimePeriod</th>\n",
       "      <th>CL_UNIT</th>\n",
       "      <th>UNIT_MULT</th>\n",
       "      <th>DataValue</th>\n",
       "      <th>NoteRef</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>TransportSea</td>\n",
       "      <td>Exports</td>\n",
       "      <td>Affiliated</td>\n",
       "      <td>AllCountries</td>\n",
       "      <td>1999</td>\n",
       "      <td>TSI_IstTransportSeaExpAllCountriesAff_A</td>\n",
       "      <td>Exports of sea transport services; all countri...</td>\n",
       "      <td>1999</td>\n",
       "      <td>USD</td>\n",
       "      <td>6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>.....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>TransportSea</td>\n",
       "      <td>Exports</td>\n",
       "      <td>AllAffiliations</td>\n",
       "      <td>AllCountries</td>\n",
       "      <td>1999</td>\n",
       "      <td>TSI_IstTransportSeaExpAllCountriesAllAff_A</td>\n",
       "      <td>Exports of sea transport services; all countries</td>\n",
       "      <td>1999</td>\n",
       "      <td>USD</td>\n",
       "      <td>6</td>\n",
       "      <td>10489.0</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>TransportSea</td>\n",
       "      <td>Exports</td>\n",
       "      <td>Unaffiliated</td>\n",
       "      <td>AllCountries</td>\n",
       "      <td>1999</td>\n",
       "      <td>TSI_IstTransportSeaExpAllCountriesUnaff_A</td>\n",
       "      <td>Exports of sea transport services; all countri...</td>\n",
       "      <td>1999</td>\n",
       "      <td>USD</td>\n",
       "      <td>6</td>\n",
       "      <td>10489.0</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>TransportSea</td>\n",
       "      <td>Exports</td>\n",
       "      <td>UsAffiliates</td>\n",
       "      <td>AllCountries</td>\n",
       "      <td>1999</td>\n",
       "      <td>TSI_IstTransportSeaExpAllCountriesUsAff_A</td>\n",
       "      <td>Exports of sea transport services; all countri...</td>\n",
       "      <td>1999</td>\n",
       "      <td>USD</td>\n",
       "      <td>6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>.....</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>TransportSea</td>\n",
       "      <td>Exports</td>\n",
       "      <td>UsParents</td>\n",
       "      <td>AllCountries</td>\n",
       "      <td>1999</td>\n",
       "      <td>TSI_IstTransportSeaExpAllCountriesUsPar_A</td>\n",
       "      <td>Exports of sea transport services; all countri...</td>\n",
       "      <td>1999</td>\n",
       "      <td>USD</td>\n",
       "      <td>6</td>\n",
       "      <td>NaN</td>\n",
       "      <td>.....</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  TypeOfService TradeDirection      Affiliation AreaOrCountry  Year  \\\n",
       "0  TransportSea        Exports       Affiliated  AllCountries  1999   \n",
       "1  TransportSea        Exports  AllAffiliations  AllCountries  1999   \n",
       "2  TransportSea        Exports     Unaffiliated  AllCountries  1999   \n",
       "3  TransportSea        Exports     UsAffiliates  AllCountries  1999   \n",
       "4  TransportSea        Exports        UsParents  AllCountries  1999   \n",
       "\n",
       "                                 TimeSeriesId  \\\n",
       "0     TSI_IstTransportSeaExpAllCountriesAff_A   \n",
       "1  TSI_IstTransportSeaExpAllCountriesAllAff_A   \n",
       "2   TSI_IstTransportSeaExpAllCountriesUnaff_A   \n",
       "3   TSI_IstTransportSeaExpAllCountriesUsAff_A   \n",
       "4   TSI_IstTransportSeaExpAllCountriesUsPar_A   \n",
       "\n",
       "                               TimeSeriesDescription TimePeriod CL_UNIT  \\\n",
       "0  Exports of sea transport services; all countri...       1999     USD   \n",
       "1   Exports of sea transport services; all countries       1999     USD   \n",
       "2  Exports of sea transport services; all countri...       1999     USD   \n",
       "3  Exports of sea transport services; all countri...       1999     USD   \n",
       "4  Exports of sea transport services; all countri...       1999     USD   \n",
       "\n",
       "  UNIT_MULT  DataValue NoteRef  \n",
       "0         6        NaN   .....  \n",
       "1         6    10489.0          \n",
       "2         6    10489.0          \n",
       "3         6        NaN   .....  \n",
       "4         6        NaN   .....  "
      ]
     },
     "execution_count": 59,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tbl = beaapi.get_data(beakey, \"IntlServTrade\", AreaOrCountry=\"AllCountries\",TypeOfService=type_of_service, Year=\"1999\")\n",
    "tbl.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "943bcffb",
   "metadata": {},
   "source": [
    "#### IIP\n",
    "\n",
    "Similar issues as above, but now `TypeOfInvestment` are the lines in tables. Does allow all `TypeOfInvestment` for \"AllCountries\" (agg'd over countries)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "194df99b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "What parameters are needed\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ParameterName</th>\n",
       "      <th>ParameterDataType</th>\n",
       "      <th>ParameterDescription</th>\n",
       "      <th>ParameterIsRequiredFlag</th>\n",
       "      <th>ParameterDefaultValue</th>\n",
       "      <th>MultipleAcceptedFlag</th>\n",
       "      <th>AllValue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>TypeOfInvestment</td>\n",
       "      <td>string</td>\n",
       "      <td>Type of investment</td>\n",
       "      <td>0</td>\n",
       "      <td>ALL</td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Component</td>\n",
       "      <td>string</td>\n",
       "      <td>Component of changes in position</td>\n",
       "      <td>0</td>\n",
       "      <td>ALL</td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Frequency</td>\n",
       "      <td>string</td>\n",
       "      <td>A - Annual, QNSA - Quarterly not seasonally ad...</td>\n",
       "      <td>0</td>\n",
       "      <td>ALL</td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Year</td>\n",
       "      <td>string</td>\n",
       "      <td>Year requested</td>\n",
       "      <td>0</td>\n",
       "      <td>ALL</td>\n",
       "      <td>1</td>\n",
       "      <td>ALL</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      ParameterName ParameterDataType  \\\n",
       "0  TypeOfInvestment            string   \n",
       "1         Component            string   \n",
       "2         Frequency            string   \n",
       "3              Year            string   \n",
       "\n",
       "                                ParameterDescription  ParameterIsRequiredFlag  \\\n",
       "0                                 Type of investment                        0   \n",
       "1                   Component of changes in position                        0   \n",
       "2  A - Annual, QNSA - Quarterly not seasonally ad...                        0   \n",
       "3                                     Year requested                        0   \n",
       "\n",
       "  ParameterDefaultValue  MultipleAcceptedFlag AllValue  \n",
       "0                   ALL                     1      ALL  \n",
       "1                   ALL                     1      ALL  \n",
       "2                   ALL                     1      ALL  \n",
       "3                   ALL                     1      ALL  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "type_desc = \"Net international investment position excluding financial derivatives\"\n",
    "\n",
    "print(\"What parameters are needed\")\n",
    "display(param_infos[\"IIP\"])"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f3823438",
   "metadata": {},
   "source": [
    "Get Type of Investment"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 62,
   "id": "dd8678da",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Key</th>\n",
       "      <th>Desc</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>343</th>\n",
       "      <td>NetExclFinDeriv</td>\n",
       "      <td>U.S. net international investment position exc...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                 Key                                               Desc\n",
       "343  NetExclFinDeriv  U.S. net international investment position exc..."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# year_IIP = beaapi.get_parameter_values(beakey, 'IIP', 'Year') #if we wanted to get list of years\n",
    "iip_Type = beaapi.get_parameter_values(beakey, 'IIP', 'TypeOfInvestment')\n",
    "type_result = iip_Type[iip_Type[\"Desc\"].str.contains(type_desc.lower())] #Note descriptions don't exaclty match lines so make lower case\n",
    "display(type_result)\n",
    "type_of_inv = type_result.iloc[0,0]"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "2391b1f2",
   "metadata": {},
   "source": [
    "Get data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "0e318f64",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>TypeOfInvestment</th>\n",
       "      <th>Component</th>\n",
       "      <th>Frequency</th>\n",
       "      <th>Year</th>\n",
       "      <th>TimeSeriesId</th>\n",
       "      <th>TimeSeriesDescription</th>\n",
       "      <th>TimePeriod</th>\n",
       "      <th>CL_UNIT</th>\n",
       "      <th>UNIT_MULT</th>\n",
       "      <th>DataValue</th>\n",
       "      <th>NoteRef</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>NetExclFinDeriv</td>\n",
       "      <td>Pos</td>\n",
       "      <td>QNSA</td>\n",
       "      <td>2020</td>\n",
       "      <td>TSI_IipNetExclFinDerivPos_QNSA</td>\n",
       "      <td>U.S. net international investment position exc...</td>\n",
       "      <td>2020Q1</td>\n",
       "      <td>USD</td>\n",
       "      <td>6</td>\n",
       "      <td>-12150967</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>NetExclFinDeriv</td>\n",
       "      <td>Pos</td>\n",
       "      <td>QNSA</td>\n",
       "      <td>2020</td>\n",
       "      <td>TSI_IipNetExclFinDerivPos_QNSA</td>\n",
       "      <td>U.S. net international investment position exc...</td>\n",
       "      <td>2020Q2</td>\n",
       "      <td>USD</td>\n",
       "      <td>6</td>\n",
       "      <td>-13018024</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>NetExclFinDeriv</td>\n",
       "      <td>Pos</td>\n",
       "      <td>QNSA</td>\n",
       "      <td>2020</td>\n",
       "      <td>TSI_IipNetExclFinDerivPos_QNSA</td>\n",
       "      <td>U.S. net international investment position exc...</td>\n",
       "      <td>2020Q3</td>\n",
       "      <td>USD</td>\n",
       "      <td>6</td>\n",
       "      <td>-13794338</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>NetExclFinDeriv</td>\n",
       "      <td>Pos</td>\n",
       "      <td>QNSA</td>\n",
       "      <td>2020</td>\n",
       "      <td>TSI_IipNetExclFinDerivPos_QNSA</td>\n",
       "      <td>U.S. net international investment position exc...</td>\n",
       "      <td>2020Q4</td>\n",
       "      <td>USD</td>\n",
       "      <td>6</td>\n",
       "      <td>-14004615</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  TypeOfInvestment Component Frequency  Year                    TimeSeriesId  \\\n",
       "0  NetExclFinDeriv       Pos      QNSA  2020  TSI_IipNetExclFinDerivPos_QNSA   \n",
       "1  NetExclFinDeriv       Pos      QNSA  2020  TSI_IipNetExclFinDerivPos_QNSA   \n",
       "2  NetExclFinDeriv       Pos      QNSA  2020  TSI_IipNetExclFinDerivPos_QNSA   \n",
       "3  NetExclFinDeriv       Pos      QNSA  2020  TSI_IipNetExclFinDerivPos_QNSA   \n",
       "\n",
       "                               TimeSeriesDescription TimePeriod CL_UNIT  \\\n",
       "0  U.S. net international investment position exc...     2020Q1     USD   \n",
       "1  U.S. net international investment position exc...     2020Q2     USD   \n",
       "2  U.S. net international investment position exc...     2020Q3     USD   \n",
       "3  U.S. net international investment position exc...     2020Q4     USD   \n",
       "\n",
       "  UNIT_MULT  DataValue NoteRef  \n",
       "0         6  -12150967          \n",
       "1         6  -13018024          \n",
       "2         6  -13794338          \n",
       "3         6  -14004615          "
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tbl = beaapi.get_data(beakey, \"IIP\", AreaOrCountry=\"AllCountries\",TypeOfInvestment=type_of_inv,Year=\"2020\",Frequency=\"QNSA\")\n",
    "tbl.head()"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d3578bb0",
   "metadata": {},
   "source": [
    "### Direct Investment & MNEs\n",
    "See the separate guide iTables_MNE"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fce2ad6c",
   "metadata": {},
   "source": [
    "### Regional"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 64,
   "id": "484aa4e6",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "What parameters are needed\n"
     ]
    },
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>ParameterName</th>\n",
       "      <th>ParameterDataType</th>\n",
       "      <th>ParameterDescription</th>\n",
       "      <th>ParameterIsRequiredFlag</th>\n",
       "      <th>MultipleAcceptedFlag</th>\n",
       "      <th>ParameterDefaultValue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>GeoFips</td>\n",
       "      <td>string</td>\n",
       "      <td>Comma-delimited list of 5-character geographic...</td>\n",
       "      <td>1</td>\n",
       "      <td>1</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>LineCode</td>\n",
       "      <td>integer</td>\n",
       "      <td>Line code for a statistic or industry</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>TableName</td>\n",
       "      <td>string</td>\n",
       "      <td>Regional income or product table to retrieve</td>\n",
       "      <td>1</td>\n",
       "      <td>0</td>\n",
       "      <td></td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Year</td>\n",
       "      <td>string</td>\n",
       "      <td>Comma-delimted list of years; LAST5 for latest...</td>\n",
       "      <td>0</td>\n",
       "      <td>1</td>\n",
       "      <td>LAST5</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  ParameterName ParameterDataType  \\\n",
       "0       GeoFips            string   \n",
       "1      LineCode           integer   \n",
       "2     TableName            string   \n",
       "3          Year            string   \n",
       "\n",
       "                                ParameterDescription  ParameterIsRequiredFlag  \\\n",
       "0  Comma-delimited list of 5-character geographic...                        1   \n",
       "1              Line code for a statistic or industry                        1   \n",
       "2       Regional income or product table to retrieve                        1   \n",
       "3  Comma-delimted list of years; LAST5 for latest...                        0   \n",
       "\n",
       "   MultipleAcceptedFlag ParameterDefaultValue  \n",
       "0                     1                  <NA>  \n",
       "1                     0                  <NA>  \n",
       "2                     0                        \n",
       "3                     1                 LAST5  "
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# Regional actually has the table name at the end of the description, so no need for get_table_param_from_desc()!\n",
    "table_param_val= \"SQGDP1\"\n",
    "year=\"2021\"\n",
    "\n",
    "print(\"What parameters are needed\")\n",
    "display(param_infos[\"Regional\"])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "569e1b32",
   "metadata": {},
   "outputs": [],
   "source": [
    "linecode=\"ALL\" # Mentioned in PDF\n",
    "# Otherwise, could do\n",
    "# pos_line_codes = beaapi.get_parameter_values_filtered(beakey, \"Regional\", \"LineCode\", TableName=table_param_val)\n",
    "# display(pos_line_codes)\n",
    "\n",
    "geo_fips = \"00000\" # Note: Not mentioned in docs, but common. See pdf for other common values\n",
    "# Otherwise, could do\n",
    "# pos_geo_codes = beaapi.get_parameter_values_filtered(beakey, \"Regional\", \"GeoFips\", TableName=table_param_val, LineCode=linecode)\n",
    "# display(pos_geo_codes)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1e30da8a",
   "metadata": {},
   "source": [
    "Get data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 66,
   "id": "66e58725",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style scoped>\n",
       "    .dataframe tbody tr th:only-of-type {\n",
       "        vertical-align: middle;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: right;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Code</th>\n",
       "      <th>GeoFips</th>\n",
       "      <th>GeoName</th>\n",
       "      <th>TimePeriod</th>\n",
       "      <th>Description</th>\n",
       "      <th>CL_UNIT</th>\n",
       "      <th>UNIT_MULT</th>\n",
       "      <th>DataValue</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>SQGDP1-3</td>\n",
       "      <td>00000</td>\n",
       "      <td>United States</td>\n",
       "      <td>2021Q1</td>\n",
       "      <td>Current-dollar GDP (millions of current dollars)</td>\n",
       "      <td>Millions of current dollars</td>\n",
       "      <td>6</td>\n",
       "      <td>22038226.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>SQGDP1-3</td>\n",
       "      <td>00000</td>\n",
       "      <td>United States</td>\n",
       "      <td>2021Q2</td>\n",
       "      <td>Current-dollar GDP (millions of current dollars)</td>\n",
       "      <td>Millions of current dollars</td>\n",
       "      <td>6</td>\n",
       "      <td>22740959.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>SQGDP1-3</td>\n",
       "      <td>00000</td>\n",
       "      <td>United States</td>\n",
       "      <td>2021Q3</td>\n",
       "      <td>Current-dollar GDP (millions of current dollars)</td>\n",
       "      <td>Millions of current dollars</td>\n",
       "      <td>6</td>\n",
       "      <td>23202344.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>SQGDP1-3</td>\n",
       "      <td>00000</td>\n",
       "      <td>United States</td>\n",
       "      <td>2021Q4</td>\n",
       "      <td>Current-dollar GDP (millions of current dollars)</td>\n",
       "      <td>Millions of current dollars</td>\n",
       "      <td>6</td>\n",
       "      <td>24002815.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>SQGDP1-1</td>\n",
       "      <td>00000</td>\n",
       "      <td>United States</td>\n",
       "      <td>2021Q1</td>\n",
       "      <td>Real GDP (millions of chained 2012 dollars)</td>\n",
       "      <td>Millions of chained 2012 dollars</td>\n",
       "      <td>6</td>\n",
       "      <td>19055655.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "       Code GeoFips        GeoName TimePeriod  \\\n",
       "0  SQGDP1-3   00000  United States     2021Q1   \n",
       "1  SQGDP1-3   00000  United States     2021Q2   \n",
       "2  SQGDP1-3   00000  United States     2021Q3   \n",
       "3  SQGDP1-3   00000  United States     2021Q4   \n",
       "4  SQGDP1-1   00000  United States     2021Q1   \n",
       "\n",
       "                                        Description  \\\n",
       "0  Current-dollar GDP (millions of current dollars)   \n",
       "1  Current-dollar GDP (millions of current dollars)   \n",
       "2  Current-dollar GDP (millions of current dollars)   \n",
       "3  Current-dollar GDP (millions of current dollars)   \n",
       "4     Real GDP (millions of chained 2012 dollars)     \n",
       "\n",
       "                            CL_UNIT  UNIT_MULT   DataValue  \n",
       "0       Millions of current dollars          6  22038226.0  \n",
       "1       Millions of current dollars          6  22740959.0  \n",
       "2       Millions of current dollars          6  23202344.0  \n",
       "3       Millions of current dollars          6  24002815.0  \n",
       "4  Millions of chained 2012 dollars          6  19055655.0  "
      ]
     },
     "execution_count": 66,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "tbl = beaapi.get_data(beakey, \"Regional\", TableName=table_param_val, Year=year, GeoFips=geo_fips, LineCode=linecode)\n",
    "tbl.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6c51a577",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "interpreter": {
   "hash": "3c9907f9837f8fbac817b619621da8348a3595d01da46bba5efff677c77201ab"
  },
  "kernelspec": {
   "display_name": "Python 3.8.12 ('BEA_API')",
   "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.8.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
