{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Generate citations automatically"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "import beaapi\n",
    "from datetime import datetime\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "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": "code",
   "execution_count": 59,
   "metadata": {},
   "outputs": [],
   "source": [
    "bibtex_str_template = \"\"\"@misc{{{0},\n",
    "    title        = \"{1}\",\n",
    "    author       = \"{{U.S.}} {{B}}ureau of {{E}}conomic {{A}}nalysis\",\n",
    "    year         = {2},\n",
    "    note         = \"Accessed: {3}\"\n",
    "}}\n",
    "\"\"\"\n",
    "formatted_template = \"U.S. Bureau of Economic Analysis, “{0},” (accessed {1}).\"\n",
    "def citation_named(table_name, cite_suffix=\"\"):\n",
    "    # Generates a single-line formatted cite and bibtek entry to manually import.\n",
    "    now  = datetime.today()\n",
    "    access_date = now.strftime('%Y-%m-%d')\n",
    "    formatted = formatted_template.format(table_name, access_date)\n",
    "    citekey = \"bea\"+cite_suffix\n",
    "\n",
    "    bibtex_str = bibtex_str_template.format(citekey, table_name, now.strftime('%Y'), access_date)\n",
    "    # howpublished = \"\\\\url{{https://www.nasa.gov/nh/pluto-the-other-red-planet}}\",\n",
    "    return (formatted, bibtex_str)\n",
    "\n",
    "def citation_search(tableid, beakey):\n",
    "    # get's tablename from metadata_search, only for NIPA, NIUnderlyingDetail and FixedAssets\n",
    "    search_data = beaapi.search_metadata(tableid, beakey)\n",
    "    table_name2 = search_data[search_data[\"TableId\"]==tableid]['TableName'].iloc[0]\n",
    "    return(citation_named(table_name2, tableid))"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Next we'll go through each dataset and try to generate one"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Working"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [],
   "source": [
    "# NIPA\n",
    "tableid = 'T20305'\n",
    "bea_tbl = beaapi.get_data(beakey, datasetname='NIPA', TableName=tableid, Frequency='Q', Year='2015')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys(['params', 'response_size', 'detail', 'time_invariant_keys', 'time_invariant_vars', 'time_variant_keys', 'time_variant_vars', 'time_variant_only_vars', 'index_cols'])\n",
      "Extra detail keys:dict_keys(['Statistic', 'UTCProductionTime', 'Dimensions', 'Notes'])\n",
      "Let's look at some interesting ones.\n",
      "Statistic: NIPA Table\n",
      "Notes corresponding to NoteRef:\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>NoteRef</th>\n",
       "      <th>NoteText</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>T20305</td>\n",
       "      <td>Table 2.3.5. Personal Consumption Expenditures...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>T20305.1</td>\n",
       "      <td>1. Net expenses of NPISHs, defined as their gr...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>T20305.2</td>\n",
       "      <td>2. Gross output is net of unrelated sales, sec...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>T20305.3</td>\n",
       "      <td>3. Excludes unrelated sales, secondary sales, ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>T20305.4</td>\n",
       "      <td>4. Food consists of food and beverages purchas...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>T20305.5</td>\n",
       "      <td>5. Consists of gasoline and other energy goods...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>T20305.6</td>\n",
       "      <td>6. Market-based PCE is a supplemental measure ...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "    NoteRef                                           NoteText\n",
       "0    T20305  Table 2.3.5. Personal Consumption Expenditures...\n",
       "1  T20305.1  1. Net expenses of NPISHs, defined as their gr...\n",
       "2  T20305.2  2. Gross output is net of unrelated sales, sec...\n",
       "3  T20305.3  3. Excludes unrelated sales, secondary sales, ...\n",
       "4  T20305.4  4. Food consists of food and beverages purchas...\n",
       "5  T20305.5  5. Consists of gasoline and other energy goods...\n",
       "6  T20305.6  6. Market-based PCE is a supplemental measure ..."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "# check out if any attrs might be helpful\n",
    "print(bea_tbl.attrs.keys())\n",
    "print('Extra detail keys:' + str(bea_tbl.attrs['detail'].keys()))\n",
    "print(bea_tbl.attrs['detail'])\n",
    "display(bea_tbl.attrs['detail']['Notes'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 41,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Table 2.3.5. Personal Consumption Expenditures by Major Type of Product [Billions of dollars] - LastRevised: September 29, 2022\n",
      "U.S. Bureau of Economic Analysis, “Table 2.3.5. Personal Consumption Expenditures by Major Type of Product,” (accessed 2022-10-18).\n",
      "@misc{beaT20305,\n",
      "    title        = \"Table 2.3.5. Personal Consumption Expenditures by Major Type of Product\",\n",
      "    author       = \"{U.S.} {B}ureau of {E}conomic {A}nalysis\",\n",
      "    year         = 2022,\n",
      "    note         = \"Accessed: 2022-10-18\"\n",
      "}\n",
      "    \n"
     ]
    }
   ],
   "source": [
    "# Two methods. The second one looks better as we don't have to parse out the units and LastRevised\n",
    "table_name1 = bea_tbl.attrs['detail']['Notes'].iloc[0,1]\n",
    "print(table_name1)\n",
    "\n",
    "\n",
    "formatted, bibtex_str = citation_search(tableid, beakey)\n",
    "print(formatted)\n",
    "print(bibtex_str)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "Now just use the metadata search for NIUnderlyingDetail and FixedAssets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Table 1AU. Real Manufacturing and Trade Inventories, Seasonally Adjusted, End of Period [Chained 1996 dollars, 1967-96, SIC] [Millions of chained (1996) dollars; seasonally adjusted, end of period] - LastRevised: July 27, 2018\n",
      "U.S. Bureau of Economic Analysis, “Table 1AU. Real Manufacturing and Trade Inventories, Seasonally Adjusted, End of Period [Chained 1996 dollars, 1967-96, SIC],” (accessed 2022-10-18).\n",
      "@misc{beaU001A,\n",
      "    title        = \"Table 1AU. Real Manufacturing and Trade Inventories, Seasonally Adjusted, End of Period [Chained 1996 dollars, 1967-96, SIC]\",\n",
      "    author       = \"{U.S.} {B}ureau of {E}conomic {A}nalysis\",\n",
      "    year         = 2022,\n",
      "    note         = \"Accessed: 2022-10-18\"\n",
      "}\n",
      "    \n"
     ]
    }
   ],
   "source": [
    "# NIUnderlyingDetail\n",
    "TableName=\"U001A\"\n",
    "bea_tbl = beaapi.get_data(beakey, datasetname='NIUnderlyingDetail', TableName=TableName, Frequency='Q', Year='1995')\n",
    "print(bea_tbl.attrs['detail']['Notes'].iloc[0,1])\n",
    "formatted, bibtex_str = citation_search(TableName, beakey)\n",
    "print(formatted)\n",
    "print(bibtex_str)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 45,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Table 1.1. Current-Cost Net Stock of Fixed Assets and Consumer Durable Goods [Billions of dollars; yearend estimates] - LastRevised: September 30, 2022\n",
      "U.S. Bureau of Economic Analysis, “Table 1.1. Current-Cost Net Stock of Fixed Assets and Consumer Durable Goods,” (accessed 2022-10-18).\n",
      "@misc{beaFAAt101,\n",
      "    title        = \"Table 1.1. Current-Cost Net Stock of Fixed Assets and Consumer Durable Goods\",\n",
      "    author       = \"{U.S.} {B}ureau of {E}conomic {A}nalysis\",\n",
      "    year         = 2022,\n",
      "    note         = \"Accessed: 2022-10-18\"\n",
      "}\n",
      "    \n"
     ]
    }
   ],
   "source": [
    "# FixedAssets\n",
    "TableName=\"FAAt101\"\n",
    "bea_tbl = beaapi.get_data(beakey, datasetname='FixedAssets', TableName=TableName, Year='2013')\n",
    "print(bea_tbl.attrs['detail']['Notes'].iloc[0,1])\n",
    "formatted, bibtex_str = citation_search(TableName, beakey)\n",
    "print(formatted)\n",
    "print(bibtex_str)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For regional we try a different approach"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 54,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys(['params', 'response_size', 'detail', 'time_invariant_keys', 'time_invariant_vars', 'time_variant_keys', 'time_variant_vars', 'time_variant_only_vars', 'index_cols'])\n",
      "Extra detail keys:dict_keys(['Statistic', 'UnitOfMeasure', 'PublicTable', 'UTCProductionTime', 'NoteRef', 'Dimensions', 'Notes'])\n",
      "{'Statistic': 'Population', 'UnitOfMeasure': 'Number of persons', 'PublicTable': 'CAINC1 County and MSA personal income summary: personal income, population, per capita personal income', 'UTCProductionTime': '2022-10-18T20:18:33.067', 'NoteRef': '1', 'Dimensions':          Name DataType  IsValue\n",
      "0        Code   string        0\n",
      "1     GeoFips   string        0\n",
      "2     GeoName   string        0\n",
      "3  TimePeriod   string        0\n",
      "4   DataValue  numeric        1\n",
      "5     CL_UNIT   string        0\n",
      "6   UNIT_MULT  numeric        0, 'Notes':   NoteRef                                           NoteText\n",
      "0       1  Census Bureau midyear population estimates. Es...\n",
      "1          Metropolitan Areas are defined (geographically...\n",
      "2   Note.  All dollar estimates are in thousands of curre...\n",
      "3          Last updated: November 16, 2021-- new statisti...}\n",
      "Notes corresponding to NoteRef:\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>NoteRef</th>\n",
       "      <th>NoteText</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>Census Bureau midyear population estimates. Es...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td></td>\n",
       "      <td>Metropolitan Areas are defined (geographically...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Note.</td>\n",
       "      <td>All dollar estimates are in thousands of curre...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td></td>\n",
       "      <td>Last updated: November 16, 2021-- new statisti...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  NoteRef                                           NoteText\n",
       "0       1  Census Bureau midyear population estimates. Es...\n",
       "1          Metropolitan Areas are defined (geographically...\n",
       "2   Note.  All dollar estimates are in thousands of curre...\n",
       "3          Last updated: November 16, 2021-- new statisti..."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#Regional\n",
    "tablename=\"CAINC1\"\n",
    "spec = {\"TableName\":tablename,\"LineCode\":\"2\",\"Year\":\"2012,2013\",\"GeoFips\":\"09003,53033\"}\n",
    "bea_tbl = beaapi.get_data(beakey, 'Regional', **spec)\n",
    "\n",
    "# check out attrs\n",
    "print(bea_tbl.attrs.keys())\n",
    "print('Extra detail keys:' + str(bea_tbl.attrs['detail'].keys()))\n",
    "print(bea_tbl.attrs['detail'])\n",
    "print(\"Notes corresponding to NoteRef:\")\n",
    "display(bea_tbl.attrs['detail']['Notes'])\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 58,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "U.S. Bureau of Economic Analysis, “CAINC1 County and MSA personal income summary: personal income, population, per capita personal income,” (accessed 2022-10-18).\n",
      "@misc{beaCAINC1,\n",
      "    title        = \"CAINC1 County and MSA personal income summary: personal income, population, per capita personal income\",\n",
      "    author       = \"{U.S.} {B}ureau of {E}conomic {A}nalysis\",\n",
      "    year         = 2022,\n",
      "    note         = \"Accessed: 2022-10-18\"\n",
      "}\n",
      "\n"
     ]
    }
   ],
   "source": [
    "formatted, bibtex_str = citation_named(bea_tbl.attrs['detail']['PublicTable'], cite_suffix=tablename)\n",
    "print(formatted)\n",
    "print(bibtex_str)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Not working"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "For the rest, we can't use metadata search and none of the attrs['detail'] are helpful"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "underlyinggdpbyindustry currenty only returns Annual results (even if you ask for additional frequencies).\n",
      "dict_keys(['params', 'response_size', 'detail', 'time_invariant_keys', 'time_invariant_vars', 'time_variant_keys', 'time_variant_vars', 'time_variant_only_vars', 'index_cols'])\n",
      "Extra detail keys:dict_keys(['Statistic', 'UTCProductionTime', 'Dimensions', 'Notes'])\n",
      "{'Statistic': 'GDP by Industry Table', 'UTCProductionTime': '2022-10-18T20:17:30.463', 'Dimensions':    Ordinal                 Name DataType  IsValue\n",
      "0        1              TableID  numeric        0\n",
      "1        2            Frequency   string        0\n",
      "2        3                 Year   string        0\n",
      "3        4              Quarter   string        0\n",
      "4        5             Industry   string        0\n",
      "5        6  IndustryDescription   string        0\n",
      "6        7            DataValue  numeric        1, 'Notes':       NoteRef                                           NoteText\n",
      "0   210.1.A,Q  1. Consists of agriculture, forestry, fishing,...\n",
      "1   210.2.A,Q  2. Consists of utilities; wholesale trade; ret...\n",
      "2   210.3.A,Q  3. Consists of computer and electronic product...\n",
      "3   210.0.A,Q  Note. Detail may not add to total due to round...\n",
      "4   210.0.A,Q  Note. The Bureau of Economic Analysis does not...\n",
      "5         210    U.Value Added by Industry [Billions of dollars]\n",
      "6   211.1.A,Q  1. Consists of agriculture, forestry, fishing,...\n",
      "7   211.2.A,Q  2. Consists of utilities; wholesale trade; ret...\n",
      "8   211.3.A,Q  3. Consists of computer and electronic product...\n",
      "9   211.0.A,Q  Note. Detail may not add to total due to round...\n",
      "10  211.0.A,Q  Note. The Bureau of Economic Analysis does not...\n",
      "11        211  U.Value added by Industry as a Percentage of G...}\n",
      "Notes corresponding to NoteRef:\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>NoteRef</th>\n",
       "      <th>NoteText</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>210.1.A,Q</td>\n",
       "      <td>1. Consists of agriculture, forestry, fishing,...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>210.2.A,Q</td>\n",
       "      <td>2. Consists of utilities; wholesale trade; ret...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>210.3.A,Q</td>\n",
       "      <td>3. Consists of computer and electronic product...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>210.0.A,Q</td>\n",
       "      <td>Note. Detail may not add to total due to round...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>210.0.A,Q</td>\n",
       "      <td>Note. The Bureau of Economic Analysis does not...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>210</td>\n",
       "      <td>U.Value Added by Industry [Billions of dollars]</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>211.1.A,Q</td>\n",
       "      <td>1. Consists of agriculture, forestry, fishing,...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>211.2.A,Q</td>\n",
       "      <td>2. Consists of utilities; wholesale trade; ret...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>211.3.A,Q</td>\n",
       "      <td>3. Consists of computer and electronic product...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>211.0.A,Q</td>\n",
       "      <td>Note. Detail may not add to total due to round...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>211.0.A,Q</td>\n",
       "      <td>Note. The Bureau of Economic Analysis does not...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>211</td>\n",
       "      <td>U.Value added by Industry as a Percentage of G...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "      NoteRef                                           NoteText\n",
       "0   210.1.A,Q  1. Consists of agriculture, forestry, fishing,...\n",
       "1   210.2.A,Q  2. Consists of utilities; wholesale trade; ret...\n",
       "2   210.3.A,Q  3. Consists of computer and electronic product...\n",
       "3   210.0.A,Q  Note. Detail may not add to total due to round...\n",
       "4   210.0.A,Q  Note. The Bureau of Economic Analysis does not...\n",
       "5         210    U.Value Added by Industry [Billions of dollars]\n",
       "6   211.1.A,Q  1. Consists of agriculture, forestry, fishing,...\n",
       "7   211.2.A,Q  2. Consists of utilities; wholesale trade; ret...\n",
       "8   211.3.A,Q  3. Consists of computer and electronic product...\n",
       "9   211.0.A,Q  Note. Detail may not add to total due to round...\n",
       "10  211.0.A,Q  Note. The Bureau of Economic Analysis does not...\n",
       "11        211  U.Value added by Industry as a Percentage of G..."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#underlyingGDPbyIndustry\n",
    "spec = {\"Year\":\"2013,2012\",\"Industry\":\"ALL\",\"tableID\":\"210,211\",\"Frequency\":\"A,Q\"}\n",
    "bea_tbl = beaapi.get_data(beakey, 'underlyingGDPbyIndustry', **spec)\n",
    "\n",
    "# check out attrs\n",
    "print(bea_tbl.attrs.keys())\n",
    "print('Extra detail keys:' + str(bea_tbl.attrs['detail'].keys()))\n",
    "print(bea_tbl.attrs['detail'])\n",
    "print(\"Notes corresponding to NoteRef:\")\n",
    "display(bea_tbl.attrs['detail']['Notes'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 52,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys(['params', 'response_size', 'detail', 'time_invariant_keys', 'time_invariant_vars', 'time_variant_keys', 'time_variant_vars', 'time_variant_only_vars', 'index_cols'])\n",
      "Extra detail keys:dict_keys(['Statistic', 'UTCProductionTime', 'Dimensions', 'Notes'])\n",
      "{'Statistic': 'GDP by Industry Table', 'UTCProductionTime': '2022-10-18T20:13:58.440', 'Dimensions':    Ordinal                 Name DataType  IsValue\n",
      "0        1              TableID  numeric        0\n",
      "1        2            Frequency   string        0\n",
      "2        3                 Year   string        0\n",
      "3        4              Quarter   string        0\n",
      "4        5             Industry   string        0\n",
      "5        6  IndustryDescription   string        0\n",
      "6        7            DataValue  numeric        1, 'Notes':    NoteRef                                           NoteText\n",
      "0  1.1.A,Q  1. Consists of agriculture, forestry, fishing,...\n",
      "1  1.2.A,Q  2. Consists of utilities; wholesale trade; ret...\n",
      "2  1.3.A,Q  3. Consists of computer and electronic product...\n",
      "3  1.0.A,Q  Note. Detail may not add to total due to round...\n",
      "4        1      Value Added by Industry [Billions of dollars]}\n",
      "Notes corresponding to NoteRef:\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>NoteRef</th>\n",
       "      <th>NoteText</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1.1.A,Q</td>\n",
       "      <td>1. Consists of agriculture, forestry, fishing,...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>1.2.A,Q</td>\n",
       "      <td>2. Consists of utilities; wholesale trade; ret...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>1.3.A,Q</td>\n",
       "      <td>3. Consists of computer and electronic product...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1.0.A,Q</td>\n",
       "      <td>Note. Detail may not add to total due to round...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>1</td>\n",
       "      <td>Value Added by Industry [Billions of dollars]</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   NoteRef                                           NoteText\n",
       "0  1.1.A,Q  1. Consists of agriculture, forestry, fishing,...\n",
       "1  1.2.A,Q  2. Consists of utilities; wholesale trade; ret...\n",
       "2  1.3.A,Q  3. Consists of computer and electronic product...\n",
       "3  1.0.A,Q  Note. Detail may not add to total due to round...\n",
       "4        1      Value Added by Industry [Billions of dollars]"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#GDPbyIndustry\n",
    "spec = {'Year':'2012,2011','Industry':'ALL','tableID':'1, 2', \"Frequency\":\"A,Q\"}\n",
    "bea_tbl = beaapi.get_data(beakey, 'GDPbyIndustry', **spec)\n",
    "\n",
    "# check out attrs\n",
    "print(bea_tbl.attrs.keys())\n",
    "print('Extra detail keys:' + str(bea_tbl.attrs['detail'].keys()))\n",
    "print(bea_tbl.attrs['detail'])\n",
    "print(\"Notes corresponding to NoteRef:\")\n",
    "display(bea_tbl.attrs['detail']['Notes'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 51,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys(['params', 'response_size', 'detail', 'time_invariant_keys', 'time_invariant_vars', 'time_variant_keys', 'time_variant_vars', 'time_variant_only_vars', 'index_cols'])\n",
      "Extra detail keys:dict_keys(['TsLastUpdated', 'EarliestFullYear', 'LatestFullYear', 'Dimensions', 'Notes'])\n",
      "{'TsLastUpdated': '2022-07-07 10:00:00.000', 'EarliestFullYear': '1999', 'LatestFullYear': '2021', 'Dimensions':     Ordinal                   Name DataType  IsValue\n",
      "0         1          TypeOfService   string        0\n",
      "1         2         TradeDirection   string        0\n",
      "2         3            Affiliation   string        0\n",
      "3         4          AreaOrCountry   string        0\n",
      "4         5                   Year   string        0\n",
      "5         6           TimeSeriesId   string        0\n",
      "6         7  TimeSeriesDescription   string        0\n",
      "7         8             TimePeriod   string        0\n",
      "8         9                CL_UNIT   string        0\n",
      "9        10              UNIT_MULT   string        0\n",
      "10       11              DataValue  numeric        1, 'Notes':          NoteRef                                           NoteText\n",
      "0            (D)  Suppressed to avoid the disclosure of data of ...\n",
      "1  IntlServ2.3:1  Courier services are included in \"Air transpor...\n",
      "2  IntlServ2.3:2  Insurance services transactions are considered...\n",
      "3  IntlServ2.3:3  Outcomes of research and development include p...\n",
      "4  IntlServ2.3:4  This category includes installation, alteratio...\n",
      "5           n.a.  Transactions are possible, but data are not av...}\n",
      "Notes corresponding to NoteRef:\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>NoteRef</th>\n",
       "      <th>NoteText</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>(D)</td>\n",
       "      <td>Suppressed to avoid the disclosure of data of ...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>IntlServ2.3:1</td>\n",
       "      <td>Courier services are included in \"Air transpor...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>IntlServ2.3:2</td>\n",
       "      <td>Insurance services transactions are considered...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>IntlServ2.3:3</td>\n",
       "      <td>Outcomes of research and development include p...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>IntlServ2.3:4</td>\n",
       "      <td>This category includes installation, alteratio...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>n.a.</td>\n",
       "      <td>Transactions are possible, but data are not av...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "         NoteRef                                           NoteText\n",
       "0            (D)  Suppressed to avoid the disclosure of data of ...\n",
       "1  IntlServ2.3:1  Courier services are included in \"Air transpor...\n",
       "2  IntlServ2.3:2  Insurance services transactions are considered...\n",
       "3  IntlServ2.3:3  Outcomes of research and development include p...\n",
       "4  IntlServ2.3:4  This category includes installation, alteratio...\n",
       "5           n.a.  Transactions are possible, but data are not av..."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#IntlServTrade\n",
    "spec = {\"AreaOrCountry\":\"Germany\",\"Year\":\"1999,2000\"}\n",
    "bea_tbl = beaapi.get_data(beakey, 'IntlServTrade', **spec)\n",
    "\n",
    "# check out attrs\n",
    "print(bea_tbl.attrs.keys())\n",
    "print('Extra detail keys:' + str(bea_tbl.attrs['detail'].keys()))\n",
    "print(bea_tbl.attrs['detail'])\n",
    "print(\"Notes corresponding to NoteRef:\")\n",
    "display(bea_tbl.attrs['detail']['Notes'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 50,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys(['params', 'response_size', 'detail', 'time_invariant_keys', 'time_invariant_vars', 'time_variant_keys', 'time_variant_vars', 'time_variant_only_vars', 'index_cols'])\n",
      "Extra detail keys:dict_keys(['Statistic', 'UTCProductionTime', 'Dimensions', 'Notes'])\n",
      "{'Statistic': 'Input-Output Table', 'UTCProductionTime': '2022-10-18T20:11:55.573', 'Dimensions':    Ordinal       Name DataType  IsValue\n",
      "0        1    TableID  numeric        0\n",
      "1        2       Year   string        0\n",
      "2        3    RowCode   string        0\n",
      "3        4   RowDescr   string        0\n",
      "4        5    RowType   string        0\n",
      "5        6    ColCode   string        0\n",
      "6        7   ColDescr   string        0\n",
      "7        8    ColType   string        0\n",
      "8        9  DataValue  numeric        1, 'Notes':                                             NoteText NoteRef\n",
      "0  Note. Detail may not add to total due to round...    <NA>\n",
      "1  Industry-by-Commodity Total Requirements, Afte...    6003}\n",
      "Notes corresponding to NoteRef:\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>NoteText</th>\n",
       "      <th>NoteRef</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Note. Detail may not add to total due to round...</td>\n",
       "      <td>&lt;NA&gt;</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Industry-by-Commodity Total Requirements, Afte...</td>\n",
       "      <td>6003</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                            NoteText NoteRef\n",
       "0  Note. Detail may not add to total due to round...    <NA>\n",
       "1  Industry-by-Commodity Total Requirements, Afte...    6003"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#InputOutput\n",
    "spec = {\"Year\":\"2010,2011,2012,2013\",\"tableID\":\"56\"} # Note: due to api error, only as for one table at a time\n",
    "bea_tbl = beaapi.get_data(beakey, 'InputOutput', **spec)\n",
    "\n",
    "# check out attrs\n",
    "print(bea_tbl.attrs.keys())\n",
    "print('Extra detail keys:' + str(bea_tbl.attrs['detail'].keys()))\n",
    "print(bea_tbl.attrs['detail'])\n",
    "print(\"Notes corresponding to NoteRef:\")\n",
    "display(bea_tbl.attrs['detail']['Notes'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 49,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys(['params', 'response_size', 'detail', 'time_invariant_keys', 'time_invariant_vars', 'time_variant_keys', 'time_variant_vars', 'time_variant_only_vars', 'index_cols'])\n",
      "Extra detail keys:dict_keys(['Dimensions'])\n",
      "{'Dimensions':    Ordinal                   Name DataType  IsValue\n",
      "0        1       TypeOfInvestment   string        0\n",
      "1        2              Component   string        0\n",
      "2        4              Frequency   string        0\n",
      "3        5                   Year   string        0\n",
      "4        6           TimeSeriesId   string        0\n",
      "5        7  TimeSeriesDescription   string        0\n",
      "6        8             TimePeriod   string        0\n",
      "7        9                CL_UNIT   string        0\n",
      "8       10              UNIT_MULT   string        0\n",
      "9       11              DataValue  numeric        1}\n",
      "Notes corresponding to NoteRef:\n"
     ]
    },
    {
     "ename": "KeyError",
     "evalue": "'Notes'",
     "output_type": "error",
     "traceback": [
      "\u001b[1;31m---------------------------------------------------------------------------\u001b[0m",
      "\u001b[1;31mKeyError\u001b[0m                                  Traceback (most recent call last)",
      "\u001b[1;32mc:\\Users\\bquis\\Documents\\GitHub\\base-bea-api\\docs\\citations.ipynb Cell 9\u001b[0m in \u001b[0;36m<cell line: 10>\u001b[1;34m()\u001b[0m\n\u001b[0;32m      <a href='vscode-notebook-cell:/c%3A/Users/bquis/Documents/GitHub/base-bea-api/docs/citations.ipynb#X16sZmlsZQ%3D%3D?line=7'>8</a>\u001b[0m \u001b[39mprint\u001b[39m(bea_tbl\u001b[39m.\u001b[39mattrs[\u001b[39m'\u001b[39m\u001b[39mdetail\u001b[39m\u001b[39m'\u001b[39m])\n\u001b[0;32m      <a href='vscode-notebook-cell:/c%3A/Users/bquis/Documents/GitHub/base-bea-api/docs/citations.ipynb#X16sZmlsZQ%3D%3D?line=8'>9</a>\u001b[0m \u001b[39mprint\u001b[39m(\u001b[39m\"\u001b[39m\u001b[39mNotes corresponding to NoteRef:\u001b[39m\u001b[39m\"\u001b[39m)\n\u001b[1;32m---> <a href='vscode-notebook-cell:/c%3A/Users/bquis/Documents/GitHub/base-bea-api/docs/citations.ipynb#X16sZmlsZQ%3D%3D?line=9'>10</a>\u001b[0m display(bea_tbl\u001b[39m.\u001b[39;49mattrs[\u001b[39m'\u001b[39;49m\u001b[39mdetail\u001b[39;49m\u001b[39m'\u001b[39;49m][\u001b[39m'\u001b[39;49m\u001b[39mNotes\u001b[39;49m\u001b[39m'\u001b[39;49m])\n",
      "\u001b[1;31mKeyError\u001b[0m: 'Notes'"
     ]
    }
   ],
   "source": [
    "#IIP\n",
    "spec = {\"TypeOfInvestment\":\"FinAssetsExclFinDeriv\",\"Component\":\"ALL\",\"Frequency\":\"ALL\",\"Year\":\"ALL\"}\n",
    "bea_tbl = beaapi.get_data(beakey, 'IIP', **spec)\n",
    "\n",
    "# check out attrs\n",
    "print(bea_tbl.attrs.keys())\n",
    "print('Extra detail keys:' + str(bea_tbl.attrs['detail'].keys()))\n",
    "print(bea_tbl.attrs['detail'])\n",
    "#print(\"Notes corresponding to NoteRef:\")\n",
    "#display(bea_tbl.attrs['detail']['Notes'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "dict_keys(['params', 'response_size', 'detail', 'time_invariant_keys', 'time_invariant_vars', 'time_variant_keys', 'time_variant_vars', 'time_variant_only_vars', 'index_cols'])\n",
      "Extra detail keys:dict_keys(['TsLastUpdated', 'Dimensions', 'Notes'])\n",
      "{'TsLastUpdated': '2022-09-22 08:30:00.000', 'Dimensions':    Ordinal                   Name DataType  IsValue\n",
      "0        1              Indicator   string        0\n",
      "1        2          AreaOrCountry   string        0\n",
      "2        3              Frequency   string        0\n",
      "3        4                   Year   string        0\n",
      "4        5           TimeSeriesId   string        0\n",
      "5        6  TimeSeriesDescription   string        0\n",
      "6        7             TimePeriod   string        0\n",
      "7        8                CL_UNIT   string        0\n",
      "8        9              UNIT_MULT   string        0\n",
      "9       10              DataValue  numeric        1, 'Notes':   NoteRef                                           NoteText\n",
      "0       Q  Quarterly estimates are not annualized and are...}\n",
      "Notes corresponding to NoteRef:\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>NoteRef</th>\n",
       "      <th>NoteText</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>Q</td>\n",
       "      <td>Quarterly estimates are not annualized and are...</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "  NoteRef                                           NoteText\n",
       "0       Q  Quarterly estimates are not annualized and are..."
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#ITA\n",
    "spec = {'Indicator':\"BalGds\",\"AreaOrCountry\":\"China,Brazil\",\"Frequency\":\"A,QSA,QNSA\", \"Year\":\"2011,2012\"}\n",
    "bea_tbl = beaapi.get_data(beakey, 'ITA', **spec)\n",
    "\n",
    "# check out attrs\n",
    "print(bea_tbl.attrs.keys())\n",
    "print('Extra detail keys:' + str(bea_tbl.attrs['detail'].keys()))\n",
    "print(bea_tbl.attrs['detail'])\n",
    "print(\"Notes corresponding to NoteRef:\")\n",
    "display(bea_tbl.attrs['detail']['Notes'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 47,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "DI\n",
      "dict_keys(['params', 'response_size', 'detail', 'time_invariant_keys', 'time_invariant_vars', 'time_variant_keys', 'time_variant_vars', 'time_variant_only_vars', 'index_cols'])\n",
      "Extra detail keys:dict_keys(['Table_Count', 'rowTypeID', 'InvestmentType', 'DataType', 'Entity', 'IndustryClassification', 'YearList', 'DIRECTIONOFINVESTMENT', 'OwnershipLevel', 'NonbankAffiliatesOnly', 'Tables', 'cnt', 'Dimensions', 'Notes'])\n",
      "{'Table_Count': '2', 'rowTypeID': '10', 'InvestmentType': 'U.S. Direct Investment Abroad', 'DataType': 'Balance of Payments and Direct Investment Position Data', 'Entity': 'None', 'IndustryClassification': 'NAICS', 'YearList': '2012,2011', 'DIRECTIONOFINVESTMENT': 'OUTWARD', 'OwnershipLevel': '2', 'NonbankAffiliatesOnly': '2', 'Tables': '210,211', 'cnt': '8', 'Dimensions':    Ordinal                  Name DataType  IsValue\n",
      "0        1                  Year  numeric        0\n",
      "1        2              SeriesID  numeric        0\n",
      "2        3            SeriesName   string        0\n",
      "3        4                   Row   string        0\n",
      "4        5                Column   string        0\n",
      "5        6               RowCode   string        0\n",
      "6        7            ColumnCode   string        0\n",
      "7        8            TableScale   string        0\n",
      "8        9  DataValueUnformatted   string        1\n",
      "9       10             DataValue   string        1, 'Notes':                                              NoteText   NoteRef\n",
      "0   <strong>n.s.</strong>  Not shown.  Data may no...      2.00\n",
      "1    ? The data appear on another line in this table.      4.00\n",
      "2   ? The data are not shown in this table but may...      6.00\n",
      "3   ? The data are not available, do not apply, or...      8.00\n",
      "4   <strong>(*)</strong> A nonzero value that roun...     10.00\n",
      "5   <strong>(D)</strong> indicates that the data i...     12.00\n",
      "6   Balance of payments transactions (and associat...     34.00\n",
      "7   The composition of the \"Other\" categories show...     36.00\n",
      "8           Source: U.S. Bureau of Economic Analysis      41.00\n",
      "9   1.&#x09;In 2021, the euro area includes Austri...    112.01\n",
      "10  1. The \"United Kingdom Islands, Caribbean\" is ...    113.00\n",
      "11  2. Data for the European Union (EU) reflect th...    114.00\n",
      "12  3. OPEC (Organization of Petroleum Exporting C...    115.00\n",
      "13  1.&#x09;In 2021, the euro area includes Austri...    221.00\n",
      "14  2. The ?United Kingdom Islands, Caribbean? inc...    222.00\n",
      "15  3. Prior to 2011, data were included in the Ne...    223.00\n",
      "16  4. Prior to 2011, included data for Curacao, S...    224.00\n",
      "17   5. Prior to 2011, included data for South Sudan.    225.00\n",
      "18  2. OPEC (Organization of Petroleum Exporting C...    226.00\n",
      "19  If you have a question about the availability ...  10000.00}\n",
      "Let's look at some interesting ones.\n",
      "Notes corresponding to NoteRef:\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>NoteText</th>\n",
       "      <th>NoteRef</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>&lt;strong&gt;n.s.&lt;/strong&gt;  Not shown.  Data may no...</td>\n",
       "      <td>2.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>? The data appear on another line in this table.</td>\n",
       "      <td>4.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>? The data are not shown in this table but may...</td>\n",
       "      <td>6.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>? The data are not available, do not apply, or...</td>\n",
       "      <td>8.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>&lt;strong&gt;(*)&lt;/strong&gt; A nonzero value that roun...</td>\n",
       "      <td>10.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>&lt;strong&gt;(D)&lt;/strong&gt; indicates that the data i...</td>\n",
       "      <td>12.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Balance of payments transactions (and associat...</td>\n",
       "      <td>34.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>The composition of the \"Other\" categories show...</td>\n",
       "      <td>36.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Source: U.S. Bureau of Economic Analysis</td>\n",
       "      <td>41.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>1.&amp;#x09;In 2021, the euro area includes Austri...</td>\n",
       "      <td>112.01</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>1. The \"United Kingdom Islands, Caribbean\" is ...</td>\n",
       "      <td>113.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2. Data for the European Union (EU) reflect th...</td>\n",
       "      <td>114.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>3. OPEC (Organization of Petroleum Exporting C...</td>\n",
       "      <td>115.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>1.&amp;#x09;In 2021, the euro area includes Austri...</td>\n",
       "      <td>221.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2. The ?United Kingdom Islands, Caribbean? inc...</td>\n",
       "      <td>222.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>3. Prior to 2011, data were included in the Ne...</td>\n",
       "      <td>223.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>4. Prior to 2011, included data for Curacao, S...</td>\n",
       "      <td>224.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>5. Prior to 2011, included data for South Sudan.</td>\n",
       "      <td>225.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>2. OPEC (Organization of Petroleum Exporting C...</td>\n",
       "      <td>226.00</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>If you have a question about the availability ...</td>\n",
       "      <td>10000.00</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                             NoteText   NoteRef\n",
       "0   <strong>n.s.</strong>  Not shown.  Data may no...      2.00\n",
       "1    ? The data appear on another line in this table.      4.00\n",
       "2   ? The data are not shown in this table but may...      6.00\n",
       "3   ? The data are not available, do not apply, or...      8.00\n",
       "4   <strong>(*)</strong> A nonzero value that roun...     10.00\n",
       "5   <strong>(D)</strong> indicates that the data i...     12.00\n",
       "6   Balance of payments transactions (and associat...     34.00\n",
       "7   The composition of the \"Other\" categories show...     36.00\n",
       "8           Source: U.S. Bureau of Economic Analysis      41.00\n",
       "9   1.&#x09;In 2021, the euro area includes Austri...    112.01\n",
       "10  1. The \"United Kingdom Islands, Caribbean\" is ...    113.00\n",
       "11  2. Data for the European Union (EU) reflect th...    114.00\n",
       "12  3. OPEC (Organization of Petroleum Exporting C...    115.00\n",
       "13  1.&#x09;In 2021, the euro area includes Austri...    221.00\n",
       "14  2. The ?United Kingdom Islands, Caribbean? inc...    222.00\n",
       "15  3. Prior to 2011, data were included in the Ne...    223.00\n",
       "16  4. Prior to 2011, included data for Curacao, S...    224.00\n",
       "17   5. Prior to 2011, included data for South Sudan.    225.00\n",
       "18  2. OPEC (Organization of Petroleum Exporting C...    226.00\n",
       "19  If you have a question about the availability ...  10000.00"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "#MNE\n",
    "print(\"DI\")\n",
    "spec = {'Country':'650,699', 'SeriesId':'27,30', 'DirectionOfInvestment':'Outward', \n",
    "        'Year':'2012,2011', 'Classification':'Country', 'GetFootnotes':'Yes'}\n",
    "#bea_tbl = beaapi.get_data(beakey, 'MNE', **spec)\n",
    "\n",
    "# check out attrs\n",
    "print(bea_tbl.attrs.keys())\n",
    "print('Extra detail keys:' + str(bea_tbl.attrs['detail'].keys()))\n",
    "print(bea_tbl.attrs['detail'])\n",
    "print(\"Notes corresponding to NoteRef:\")\n",
    "display(bea_tbl.attrs['detail']['Notes'])\n",
    "\n",
    "#print(\"AMNE\")\n",
    "#spec = {\"Year\":\"2012,2011\",\"Country\":\"202\",\"Industry\":\"all\",\"DirectionOfInvestment\":\"Outward\",\n",
    "#        \"Classification\":\"CountryByIndustry\",\"SeriesId\":\"5,4\",\"NonBankAffiliatesOnly\":\"0\",\"OwnershipLevel\":\"0\", 'GetFootnotes':'Yes'}\n",
    "\n"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3.9.13 ('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.9.13"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "2fd94da68bd5f03aa57a192814133d67ed1074ffddcac4a7fa0632dac99bef89"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
