<commit_before>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Introduction\n",
    "\n",
    "The Bureau of Economic Analysis (BEA) publishes economic statistics in a variety of formats. This document describes the BEA Data Retrieval Application Programming Interface (API) – including detailed instructions for retrieving data and meta-data published by BEA using the pyBEA package. \n",
    "\n",
    "The pyBEA pacakge provides a simple interface to the BEA API and includes methods for retrieving a subset of BEA statistical data, including any meta-data describing it, and loading the results into a Pandas DataFrame object for further analysis.\n",
    "\n",
    "## Data Return Format\n",
    "The BEA API returns data in one of two formats: JSON or XML (with JSON being the default). Currently the pyBEA package only supports JSON requests.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pybea"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Meta-Data API Methods\n",
    "\n",
    "The BEA API contains three methods for retrieving meta-data as follows:\n",
    "\n",
    "1. `GetDataSetList`: retrieves a list of the datasets currently offered.\n",
    "2. `GetParameterList`: retrieves a list of the parameters (required and optional) for a particular dataset.\n",
    "3. `GetParameterValues`: retrieves a list of the valid values for a particular parameter.\n",
    "\n",
    "Each of these methods has a corresponding function in the `pybea` package."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "pybea.get_data_set_list?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "pybea.get_parameter_list?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "pybea.get_parameter_values?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example usage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# replace this with your BEA data API key!\n",
    "USER_ID = '98A0A0A7-21DF-4B75-96DE-1410D47AB280'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>DatasetDescription</th>\n",
       "      <th>DatasetName</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>The RegionalData dataset is obsolete. Please u...</td>\n",
       "      <td>RegionalData</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>Standard NIPA tables</td>\n",
       "      <td>NIPA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>Standard NI underlying detail tables</td>\n",
       "      <td>NIUnderlyingDetail</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Multinational Enterprises</td>\n",
       "      <td>MNE</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Standard Fixed Assets tables</td>\n",
       "      <td>FixedAssets</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>International Transactions Accounts</td>\n",
       "      <td>ITA</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>International Investment Position</td>\n",
       "      <td>IIP</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>GDP by Industry</td>\n",
       "      <td>GDPbyIndustry</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Regional Income data sets</td>\n",
       "      <td>RegionalIncome</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Regional Product data sets</td>\n",
       "      <td>RegionalProduct</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>Input-Output Data</td>\n",
       "      <td>InputOutput</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>Underlying GDP by Industry</td>\n",
       "      <td>UnderlyingGDPbyIndustry</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>International Services Trade</td>\n",
       "      <td>IntlServTrade</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>Metadata about other API datasets</td>\n",
       "      <td>APIDatasetMetaData</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                                   DatasetDescription              DatasetName\n",
       "0   The RegionalData dataset is obsolete. Please u...             RegionalData\n",
       "1                                Standard NIPA tables                     NIPA\n",
       "2                Standard NI underlying detail tables       NIUnderlyingDetail\n",
       "3                           Multinational Enterprises                      MNE\n",
       "4                        Standard Fixed Assets tables              FixedAssets\n",
       "5                 International Transactions Accounts                      ITA\n",
       "6                   International Investment Position                      IIP\n",
       "7                                     GDP by Industry            GDPbyIndustry\n",
       "8                           Regional Income data sets           RegionalIncome\n",
       "9                          Regional Product data sets          RegionalProduct\n",
       "10                                  Input-Output Data              InputOutput\n",
       "11                         Underlying GDP by Industry  UnderlyingGDPbyIndustry\n",
       "12                       International Services Trade            IntlServTrade\n",
       "13                  Metadata about other API datasets       APIDatasetMetaData"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "# access the BEA data API...\n",
    "available_datasets = pybea.get_data_set_list(USER_ID)\n",
    "available_datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>MultipleAcceptedFlag</th>\n",
       "      <th>ParameterDataType</th>\n",
       "      <th>ParameterDefaultValue</th>\n",
       "      <th>ParameterDescription</th>\n",
       "      <th>ParameterIsRequiredFlag</th>\n",
       "      <th>ParameterName</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>1</td>\n",
       "      <td>string</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Comma-delimited list of 5-character geographic...</td>\n",
       "      <td>1</td>\n",
       "      <td>GeoFips</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>0</td>\n",
       "      <td>integer</td>\n",
       "      <td>NaN</td>\n",
       "      <td>Line code for a statistic or industry</td>\n",
       "      <td>1</td>\n",
       "      <td>LineCode</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>0</td>\n",
       "      <td>string</td>\n",
       "      <td></td>\n",
       "      <td>Income or employment table to retrieve</td>\n",
       "      <td>1</td>\n",
       "      <td>TableName</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>1</td>\n",
       "      <td>string</td>\n",
       "      <td>LAST5</td>\n",
       "      <td>Comma-delimted list of years; LAST5 for latest...</td>\n",
       "      <td>0</td>\n",
       "      <td>Year</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "   MultipleAcceptedFlag ParameterDataType ParameterDefaultValue  \\\n",
       "0                     1            string                   NaN   \n",
       "1                     0           integer                   NaN   \n",
       "2                     0            string                         \n",
       "3                     1            string                 LAST5   \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             Income or employment table to retrieve                        1   \n",
       "3  Comma-delimted list of years; LAST5 for latest...                        0   \n",
       "\n",
       "  ParameterName  \n",
       "0       GeoFips  \n",
       "1      LineCode  \n",
       "2     TableName  \n",
       "3          Year  "
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "regional_income_params = pybea.get_parameter_list(USER_ID, DataSetName='RegionalIncome')\n",
    "regional_income_params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>Desc</th>\n",
       "      <th>Key</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>United States</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>United States (Metropolitan Portion)</td>\n",
       "      <td>998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>United States (Nonmetropolitan Portion)</td>\n",
       "      <td>999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>Alabama</td>\n",
       "      <td>1000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>Autauga</td>\n",
       "      <td>1001</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>Baldwin</td>\n",
       "      <td>1003</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>Barbour</td>\n",
       "      <td>1005</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>Bibb</td>\n",
       "      <td>1007</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>Blount</td>\n",
       "      <td>1009</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>Bullock</td>\n",
       "      <td>1011</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>Butler</td>\n",
       "      <td>1013</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>Calhoun</td>\n",
       "      <td>1015</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>Chambers</td>\n",
       "      <td>1017</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>Cherokee</td>\n",
       "      <td>1019</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>Chilton</td>\n",
       "      <td>1021</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>Choctaw</td>\n",
       "      <td>1023</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>Clarke</td>\n",
       "      <td>1025</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>Clay</td>\n",
       "      <td>1027</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>Cleburne</td>\n",
       "      <td>1029</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>Coffee</td>\n",
       "      <td>1031</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>Colbert</td>\n",
       "      <td>1033</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>Conecuh</td>\n",
       "      <td>1035</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>Coosa</td>\n",
       "      <td>1037</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>Covington</td>\n",
       "      <td>1039</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>Crenshaw</td>\n",
       "      <td>1041</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>Cullman</td>\n",
       "      <td>1043</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>Dale</td>\n",
       "      <td>1045</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>Dallas</td>\n",
       "      <td>1047</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>DeKalb</td>\n",
       "      <td>1049</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>Elmore</td>\n",
       "      <td>1051</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4423</th>\n",
       "      <td>Visalia-Porterville-Hanford, CA (Combined Stat...</td>\n",
       "      <td>89546</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4424</th>\n",
       "      <td>Washington-Baltimore-Arlington, DC-MD-VA-WV-PA...</td>\n",
       "      <td>89548</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4425</th>\n",
       "      <td>Wausau-Stevens Point-Wisconsin Rapids, WI (Com...</td>\n",
       "      <td>89554</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4426</th>\n",
       "      <td>Wichita-Arkansas City-Winfield, KS (Combined S...</td>\n",
       "      <td>89556</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4427</th>\n",
       "      <td>Williamsport-Lock Haven, PA (Combined Statisti...</td>\n",
       "      <td>89558</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4428</th>\n",
       "      <td>Youngstown-Warren, OH-PA (Combined Statistical...</td>\n",
       "      <td>89566</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4429</th>\n",
       "      <td>New England</td>\n",
       "      <td>91000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4430</th>\n",
       "      <td>New England (Metropolitan Portion)</td>\n",
       "      <td>91998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4431</th>\n",
       "      <td>New England (Nonmetropolitan Portion)</td>\n",
       "      <td>91999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4432</th>\n",
       "      <td>Mideast</td>\n",
       "      <td>92000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4433</th>\n",
       "      <td>Mideast (Metropolitan Portion)</td>\n",
       "      <td>92998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4434</th>\n",
       "      <td>Mideast (Nonmetropolitan Portion)</td>\n",
       "      <td>92999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4435</th>\n",
       "      <td>Great Lakes</td>\n",
       "      <td>93000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4436</th>\n",
       "      <td>Great Lakes (Metropolitan Portion)</td>\n",
       "      <td>93998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4437</th>\n",
       "      <td>Great Lakes (Nonmetropolitan Portion)</td>\n",
       "      <td>93999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4438</th>\n",
       "      <td>Plains</td>\n",
       "      <td>94000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4439</th>\n",
       "      <td>Plains (Metropolitan Portion)</td>\n",
       "      <td>94998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4440</th>\n",
       "      <td>Plains (Nonmetropolitan Portion)</td>\n",
       "      <td>94999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4441</th>\n",
       "      <td>Southeast</td>\n",
       "      <td>95000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4442</th>\n",
       "      <td>Southeast (Metropolitan Portion)</td>\n",
       "      <td>95998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4443</th>\n",
       "      <td>Southeast (Nonmetropolitan Portion)</td>\n",
       "      <td>95999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4444</th>\n",
       "      <td>Southwest</td>\n",
       "      <td>96000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4445</th>\n",
       "      <td>Southwest (Metropolitan Portion)</td>\n",
       "      <td>96998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4446</th>\n",
       "      <td>Southwest (Nonmetropolitan Portion)</td>\n",
       "      <td>96999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4447</th>\n",
       "      <td>Rocky Mountain</td>\n",
       "      <td>97000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4448</th>\n",
       "      <td>Rocky Mountain (Metropolitan Portion)</td>\n",
       "      <td>97998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4449</th>\n",
       "      <td>Rocky Mountain (Nonmetropolitan Portion)</td>\n",
       "      <td>97999</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4450</th>\n",
       "      <td>Far West</td>\n",
       "      <td>98000</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4451</th>\n",
       "      <td>Far West (Metropolitan Portion)</td>\n",
       "      <td>98998</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4452</th>\n",
       "      <td>Far West (Nonmetropolitan Portion)</td>\n",
       "      <td>98999</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>4453 rows × 2 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "                                                   Desc    Key\n",
       "0                                         United States      0\n",
       "1                  United States (Metropolitan Portion)    998\n",
       "2               United States (Nonmetropolitan Portion)    999\n",
       "3                                               Alabama   1000\n",
       "4                                               Autauga   1001\n",
       "5                                               Baldwin   1003\n",
       "6                                               Barbour   1005\n",
       "7                                                  Bibb   1007\n",
       "8                                                Blount   1009\n",
       "9                                               Bullock   1011\n",
       "10                                               Butler   1013\n",
       "11                                              Calhoun   1015\n",
       "12                                             Chambers   1017\n",
       "13                                             Cherokee   1019\n",
       "14                                              Chilton   1021\n",
       "15                                              Choctaw   1023\n",
       "16                                               Clarke   1025\n",
       "17                                                 Clay   1027\n",
       "18                                             Cleburne   1029\n",
       "19                                               Coffee   1031\n",
       "20                                              Colbert   1033\n",
       "21                                              Conecuh   1035\n",
       "22                                                Coosa   1037\n",
       "23                                            Covington   1039\n",
       "24                                             Crenshaw   1041\n",
       "25                                              Cullman   1043\n",
       "26                                                 Dale   1045\n",
       "27                                               Dallas   1047\n",
       "28                                               DeKalb   1049\n",
       "29                                               Elmore   1051\n",
       "...                                                 ...    ...\n",
       "4423  Visalia-Porterville-Hanford, CA (Combined Stat...  89546\n",
       "4424  Washington-Baltimore-Arlington, DC-MD-VA-WV-PA...  89548\n",
       "4425  Wausau-Stevens Point-Wisconsin Rapids, WI (Com...  89554\n",
       "4426  Wichita-Arkansas City-Winfield, KS (Combined S...  89556\n",
       "4427  Williamsport-Lock Haven, PA (Combined Statisti...  89558\n",
       "4428  Youngstown-Warren, OH-PA (Combined Statistical...  89566\n",
       "4429                                        New England  91000\n",
       "4430                 New England (Metropolitan Portion)  91998\n",
       "4431              New England (Nonmetropolitan Portion)  91999\n",
       "4432                                            Mideast  92000\n",
       "4433                     Mideast (Metropolitan Portion)  92998\n",
       "4434                  Mideast (Nonmetropolitan Portion)  92999\n",
       "4435                                        Great Lakes  93000\n",
       "4436                 Great Lakes (Metropolitan Portion)  93998\n",
       "4437              Great Lakes (Nonmetropolitan Portion)  93999\n",
       "4438                                             Plains  94000\n",
       "4439                      Plains (Metropolitan Portion)  94998\n",
       "4440                   Plains (Nonmetropolitan Portion)  94999\n",
       "4441                                          Southeast  95000\n",
       "4442                   Southeast (Metropolitan Portion)  95998\n",
       "4443                Southeast (Nonmetropolitan Portion)  95999\n",
       "4444                                          Southwest  96000\n",
       "4445                   Southwest (Metropolitan Portion)  96998\n",
       "4446                Southwest (Nonmetropolitan Portion)  96999\n",
       "4447                                     Rocky Mountain  97000\n",
       "4448              Rocky Mountain (Metropolitan Portion)  97998\n",
       "4449           Rocky Mountain (Nonmetropolitan Portion)  97999\n",
       "4450                                           Far West  98000\n",
       "4451                    Far West (Metropolitan Portion)  98998\n",
       "4452                 Far West (Nonmetropolitan Portion)  98999\n",
       "\n",
       "[4453 rows x 2 columns]"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "regional_income_geofips = pybea.get_parameter_values(USER_ID, DataSetName='RegionalIncome',\n",
    "                                                     ParameterName='GeoFips')\n",
    "regional_income_geofips"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Data Retrieval API Method\n",
    "\n",
    "The BEA API has one method for retrieving data: `GetData`. This method has its own function in the `pybea` package. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "pybea.get_data?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# RegionalIncome\n",
    "\n",
    "## Example Usage\n",
    "\n",
    "Fetch data on personal income for 2012 and 2013 for all counties, in JSON format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "data = pybea.get_data(USER_ID,\n",
    "                      DataSetName='RegionalIncome',\n",
    "                      TableName='CA1',\n",
    "                      LineCode=1,\n",
    "                      GeoFips='COUNTY',\n",
    "                      Year=['2012', '2013'],\n",
    "                      )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CL_UNIT</th>\n",
       "      <th>Code</th>\n",
       "      <th>DataValue</th>\n",
       "      <th>GeoFips</th>\n",
       "      <th>GeoName</th>\n",
       "      <th>NoteRef</th>\n",
       "      <th>TimePeriod</th>\n",
       "      <th>UNIT_MULT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>13904485000</td>\n",
       "      <td>0</td>\n",
       "      <td>United States</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>14068960000</td>\n",
       "      <td>0</td>\n",
       "      <td>United States</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2013</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>172789879</td>\n",
       "      <td>1000</td>\n",
       "      <td>Alabama</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2013</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>170881367</td>\n",
       "      <td>1000</td>\n",
       "      <td>Alabama</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>1928597</td>\n",
       "      <td>1001</td>\n",
       "      <td>Autauga, AL</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                CL_UNIT   Code    DataValue  GeoFips        GeoName NoteRef  \\\n",
       "0  thousands of dollars  CA1-1  13904485000        0  United States     NaN   \n",
       "1  thousands of dollars  CA1-1  14068960000        0  United States     NaN   \n",
       "2  thousands of dollars  CA1-1    172789879     1000        Alabama     NaN   \n",
       "3  thousands of dollars  CA1-1    170881367     1000        Alabama     NaN   \n",
       "4  thousands of dollars  CA1-1      1928597     1001    Autauga, AL     NaN   \n",
       "\n",
       "   TimePeriod  UNIT_MULT  \n",
       "0        2012          3  \n",
       "1        2013          3  \n",
       "2        2013          3  \n",
       "3        2012          3  \n",
       "4        2012          3  "
      ]
     },
     "execution_count": 21,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CL_UNIT</th>\n",
       "      <th>Code</th>\n",
       "      <th>DataValue</th>\n",
       "      <th>GeoFips</th>\n",
       "      <th>GeoName</th>\n",
       "      <th>NoteRef</th>\n",
       "      <th>TimePeriod</th>\n",
       "      <th>UNIT_MULT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>6391</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>1628012943</td>\n",
       "      <td>96000</td>\n",
       "      <td>Southwest</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2013</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6392</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>461347229</td>\n",
       "      <td>97000</td>\n",
       "      <td>Rocky Mountain</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6393</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>479685748</td>\n",
       "      <td>97000</td>\n",
       "      <td>Rocky Mountain</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2013</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6394</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>2525722441</td>\n",
       "      <td>98000</td>\n",
       "      <td>Far West</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2012</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6395</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>2559477354</td>\n",
       "      <td>98000</td>\n",
       "      <td>Far West</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2013</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   CL_UNIT   Code   DataValue  GeoFips         GeoName  \\\n",
       "6391  thousands of dollars  CA1-1  1628012943    96000       Southwest   \n",
       "6392  thousands of dollars  CA1-1   461347229    97000  Rocky Mountain   \n",
       "6393  thousands of dollars  CA1-1   479685748    97000  Rocky Mountain   \n",
       "6394  thousands of dollars  CA1-1  2525722441    98000        Far West   \n",
       "6395  thousands of dollars  CA1-1  2559477354    98000        Far West   \n",
       "\n",
       "     NoteRef  TimePeriod  UNIT_MULT  \n",
       "6391     NaN        2013          3  \n",
       "6392     NaN        2012          3  \n",
       "6393     NaN        2013          3  \n",
       "6394     NaN        2012          3  \n",
       "6395     NaN        2013          3  "
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.tail()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example Usage\n",
    "\n",
    "Real per capita personal income for all states, all years, in JSON format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "data = pybea.get_data(USER_ID,\n",
    "                      DataSetName='RegionalIncome',\n",
    "                      TableName='CA1',\n",
    "                      LineCode=1,\n",
    "                      GeoFips='STATE',\n",
    "                      Year='ALL',\n",
    "                      )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CL_UNIT</th>\n",
       "      <th>Code</th>\n",
       "      <th>DataValue</th>\n",
       "      <th>GeoFips</th>\n",
       "      <th>GeoName</th>\n",
       "      <th>NoteRef</th>\n",
       "      <th>TimePeriod</th>\n",
       "      <th>UNIT_MULT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>791150000</td>\n",
       "      <td>0</td>\n",
       "      <td>United States</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1969</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>855078000</td>\n",
       "      <td>0</td>\n",
       "      <td>United States</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1970</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>923964000</td>\n",
       "      <td>0</td>\n",
       "      <td>United States</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1971</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>1015526000</td>\n",
       "      <td>0</td>\n",
       "      <td>United States</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1972</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>1131213000</td>\n",
       "      <td>0</td>\n",
       "      <td>United States</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1973</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                CL_UNIT   Code   DataValue  GeoFips        GeoName NoteRef  \\\n",
       "0  thousands of dollars  CA1-1   791150000        0  United States     NaN   \n",
       "1  thousands of dollars  CA1-1   855078000        0  United States     NaN   \n",
       "2  thousands of dollars  CA1-1   923964000        0  United States     NaN   \n",
       "3  thousands of dollars  CA1-1  1015526000        0  United States     NaN   \n",
       "4  thousands of dollars  CA1-1  1131213000        0  United States     NaN   \n",
       "\n",
       "   TimePeriod  UNIT_MULT  \n",
       "0        1969          3  \n",
       "1        1970          3  \n",
       "2        1971          3  \n",
       "3        1972          3  \n",
       "4        1973          3  "
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>CL_UNIT</th>\n",
       "      <th>Code</th>\n",
       "      <th>DataValue</th>\n",
       "      <th>GeoFips</th>\n",
       "      <th>GeoName</th>\n",
       "      <th>NoteRef</th>\n",
       "      <th>TimePeriod</th>\n",
       "      <th>UNIT_MULT</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2875</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>170172717</td>\n",
       "      <td>98000</td>\n",
       "      <td>Far West</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1973</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2876</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>154141482</td>\n",
       "      <td>98000</td>\n",
       "      <td>Far West</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1972</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2877</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>140460901</td>\n",
       "      <td>98000</td>\n",
       "      <td>Far West</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1971</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2878</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>131426091</td>\n",
       "      <td>98000</td>\n",
       "      <td>Far West</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1970</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2879</th>\n",
       "      <td>thousands of dollars</td>\n",
       "      <td>CA1-1</td>\n",
       "      <td>121614128</td>\n",
       "      <td>98000</td>\n",
       "      <td>Far West</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1969</td>\n",
       "      <td>3</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                   CL_UNIT   Code  DataValue  GeoFips   GeoName NoteRef  \\\n",
       "2875  thousands of dollars  CA1-1  170172717    98000  Far West     NaN   \n",
       "2876  thousands of dollars  CA1-1  154141482    98000  Far West     NaN   \n",
       "2877  thousands of dollars  CA1-1  140460901    98000  Far West     NaN   \n",
       "2878  thousands of dollars  CA1-1  131426091    98000  Far West     NaN   \n",
       "2879  thousands of dollars  CA1-1  121614128    98000  Far West     NaN   \n",
       "\n",
       "      TimePeriod  UNIT_MULT  \n",
       "2875        1973          3  \n",
       "2876        1972          3  \n",
       "2877        1971          3  \n",
       "2878        1970          3  \n",
       "2879        1969          3  "
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "data.tail()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# NIPA (National Income and Product Accounts)\n",
    "\n",
    "The NIPA dataset contains data from the standard set of NIPA tables as published in the Survey of Current Business. Availability of updated NIPA data follows the BEA News Release schedule as posted on the BEA web site. The NIPA dataset may be unavailable for a few minutes preceding the monthly GDP release while data is being updated (as it is for all other methods of acquiring newly released data). "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "  AllValue  MultipleAcceptedFlag ParameterDataType ParameterDefaultValue  \\\n",
      "0                              1            string                         \n",
      "1                              0            string                     N   \n",
      "2                              0           integer                   NaN   \n",
      "3                              0            string                   NaN   \n",
      "4        X                     1           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",
      "  ParameterName  \n",
      "0     Frequency  \n",
      "1  ShowMillions  \n",
      "2       TableID  \n",
      "3     TableName  \n",
      "4          Year  \n"
     ]
    }
   ],
   "source": [
    "# access the BEA data API...\n",
    "meta_data = pybea.get_parameter_list(USER_ID, DataSetName='NIPA')\n",
    "\n",
    "# ...display the resulting Pandas DataFrame\n",
    "print(meta_data)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "                                           Description TableName\n",
      "0    Table 1.1.1. Percent Change From Preceding Per...    T10101\n",
      "1    Table 1.1.2. Contributions to Percent Change i...    T10102\n",
      "2    Table 1.1.3. Real Gross Domestic Product, Quan...    T10103\n",
      "3    Table 1.1.4. Price Indexes for Gross Domestic ...    T10104\n",
      "4          Table 1.1.5. Gross Domestic Product (A) (Q)    T10105\n",
      "5    Table 1.1.6. Real Gross Domestic Product, Chai...    T10106\n",
      "6    Table 1.1.6A. Real Gross Domestic Product, Cha...   T10106A\n",
      "7    Table 1.1.6B. Real Gross Domestic Product, Cha...   T10106B\n",
      "8    Table 1.1.6C. Real Gross Domestic Product, Cha...   T10106C\n",
      "9    Table 1.1.6D. Real Gross Domestic Product, Cha...   T10106D\n",
      "10   Table 1.1.7. Percent Change From Preceding Per...    T10107\n",
      "11   Table 1.1.8. Contributions to Percent Change i...    T10108\n",
      "12   Table 1.1.9. Implicit Price Deflators for Gros...    T10109\n",
      "13   Table 1.1.10. Percentage Shares of Gross Domes...    T10110\n",
      "14   Table 1.1.11. Real Gross Domestic Product: Per...    T10111\n",
      "15   Table 1.2.1. Percent Change From Preceding Per...    T10201\n",
      "16   Table 1.2.2. Contributions to Percent Change i...    T10202\n",
      "17   Table 1.2.3. Real Gross Domestic Product by Ma...    T10203\n",
      "18   Table 1.2.4. Price Indexes for Gross Domestic ...    T10204\n",
      "19   Table 1.2.5. Gross Domestic Product by Major T...    T10205\n",
      "20   Table 1.2.6. Real Gross Domestic Product by Ma...    T10206\n",
      "21   Table 1.3.1. Percent Change From Preceding Per...    T10301\n",
      "22   Table 1.3.3. Real Gross Value Added by Sector,...    T10303\n",
      "23   Table 1.3.4. Price Indexes for Gross Value Add...    T10304\n",
      "24    Table 1.3.5. Gross Value Added by Sector (A) (Q)    T10305\n",
      "25   Table 1.3.6. Real Gross Value Added by Sector,...    T10306\n",
      "26   Table 1.4.1. Percent Change From Preceding Per...    T10401\n",
      "27   Table 1.4.3. Real Gross Domestic Product, Real...    T10403\n",
      "28   Table 1.4.4. Price Indexes for Gross Domestic ...    T10404\n",
      "29   Table 1.4.5. Relation of Gross Domestic Produc...    T10405\n",
      "..                                                 ...       ...\n",
      "282  Table 7.2.6B. Real Motor Vehicle Output, Chain...   T70206B\n",
      "283  Table 7.3.3. Real Farm Sector Output, Real Gro...    T70303\n",
      "284  Table 7.3.4. Price Indexes for Farm Sector Out...    T70304\n",
      "285  Table 7.3.5. Farm Sector Output, Gross Value A...    T70305\n",
      "286  Table 7.3.6. Real Farm Sector Output, Real Gro...    T70306\n",
      "287  Table 7.4.3. Real Housing Sector Output, Real ...    T70403\n",
      "288  Table 7.4.4. Price Indexes for Housing Sector ...    T70404\n",
      "289  Table 7.4.5. Housing Sector Output, Gross Valu...    T70405\n",
      "290  Table 7.4.6. Real Housing Sector Output, Real ...    T70406\n",
      "291  Table 7.5. Consumption of Fixed Capital by Leg...    T70500\n",
      "292  Table 7.6. Capital Consumption Adjustment by L...    T70600\n",
      "293  Table 7.7. Business Current Transfer Payments ...    T70700\n",
      "294  Table 7.8. Supplements to Wages and Salaries b...    T70800\n",
      "295  Table 7.9. Rental Income of Persons by Legal F...    T70900\n",
      "296  Table 7.10. Dividends Paid and Received by Sec...    T71000\n",
      "297  Table 7.11. Interest Paid and Received by Sect...    T71100\n",
      "298  Table 7.12. Imputations in the National Income...    T71200\n",
      "299  Table 7.13. Relation of Consumption of Fixed C...    T71300\n",
      "300  Table 7.14. Relation of Nonfarm Proprietors' I...    T71400\n",
      "301  Table 7.15. Relation of Net Farm Income in the...    T71500\n",
      "302  Table 7.16. Relation of Corporate Profits, Tax...    T71600\n",
      "303  Table 7.17. Relation of Monetary Interest Paid...    T71700\n",
      "304  Table 7.18. Relation of Wages and Salaries in ...    T71800\n",
      "305  Table 7.19. Comparison of Income and Outlays o...    T71900\n",
      "306  Table 7.20. Transactions of Defined Benefit an...    T72000\n",
      "307  Table 7.21. Transactions of Defined Benefit Pe...    T72100\n",
      "308  Table 7.22. Transactions of Private Defined Be...    T72200\n",
      "309  Table 7.23. Transactions of Federal Government...    T72300\n",
      "310  Table 7.24. Transactions of State and Local Go...    T72400\n",
      "311  Table 7.25. Transactions of Defined Contributi...    T72500\n",
      "\n",
      "[312 rows x 2 columns]\n"
     ]
    }
   ],
   "source": [
    "# access the BEA data API...\n",
    "meta_data = pybea.get_parameter_values(USER_ID,\n",
    "                                       DataSetName='NIPA',\n",
    "                                       ParameterName='TableID')\n",
    "\n",
    "# ...display the resulting Pandas DataFrame\n",
    "print(meta_data)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# NIUnderlyingDetail (National Income and Product Accounts)\n",
    "\n",
    "The NIUnderlyingDetail dataset contains detailed estimate data from underlying NIPA series that appear in the national income and product account (NIPA) tables as published in the Survey of Current Business."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Fixed Assets\n",
    "\n",
    "The FixedAssets dataset contains data from the standard set of Fixed Assets tables as published online. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}
<commit_msg>Removed API token from notebook<commit_after>{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Introduction\n",
    "\n",
    "The Bureau of Economic Analysis (BEA) publishes economic statistics in a variety of formats. This document describes the BEA Data Retrieval Application Programming Interface (API) – including detailed instructions for retrieving data and meta-data published by BEA using the pyBEA package. \n",
    "\n",
    "The pyBEA pacakge provides a simple interface to the BEA API and includes methods for retrieving a subset of BEA statistical data, including any meta-data describing it, and loading the results into a Pandas DataFrame object for further analysis.\n",
    "\n",
    "## Data Return Format\n",
    "The BEA API returns data in one of two formats: JSON or XML (with JSON being the default). Currently the pyBEA package only supports JSON requests.\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import pybea"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Meta-Data API Methods\n",
    "\n",
    "The BEA API contains three methods for retrieving meta-data as follows:\n",
    "\n",
    "1. `GetDataSetList`: retrieves a list of the datasets currently offered.\n",
    "2. `GetParameterList`: retrieves a list of the parameters (required and optional) for a particular dataset.\n",
    "3. `GetParameterValues`: retrieves a list of the valid values for a particular parameter.\n",
    "\n",
    "Each of these methods has a corresponding function in the `pybea` package."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "pybea.get_data_set_list?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "pybea.get_parameter_list?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "pybea.get_parameter_values?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### Example usage"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "# replace this with your BEA data API key!\n",
    "USER_ID = ???"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "# access the BEA data API...\n",
    "available_datasets = pybea.get_data_set_list(USER_ID)\n",
    "available_datasets"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "regional_income_params = pybea.get_parameter_list(USER_ID, DataSetName='RegionalIncome')\n",
    "regional_income_params"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "regional_income_geofips = pybea.get_parameter_values(USER_ID, DataSetName='RegionalIncome',\n",
    "                                                     ParameterName='GeoFips')\n",
    "regional_income_geofips"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Data Retrieval API Method\n",
    "\n",
    "The BEA API has one method for retrieving data: `GetData`. This method has its own function in the `pybea` package. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "pybea.get_data?"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# RegionalIncome\n",
    "\n",
    "## Example Usage\n",
    "\n",
    "Fetch data on personal income for 2012 and 2013 for all counties, in JSON format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "data = pybea.get_data(USER_ID,\n",
    "                      DataSetName='RegionalIncome',\n",
    "                      TableName='CA1',\n",
    "                      LineCode=1,\n",
    "                      GeoFips='COUNTY',\n",
    "                      Year=['2012', '2013'],\n",
    "                      )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.tail()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## Example Usage\n",
    "\n",
    "Real per capita personal income for all states, all years, in JSON format"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "data = pybea.get_data(USER_ID,\n",
    "                      DataSetName='RegionalIncome',\n",
    "                      TableName='CA1',\n",
    "                      LineCode=1,\n",
    "                      GeoFips='STATE',\n",
    "                      Year='ALL',\n",
    "                      )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.head()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "data.tail()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# NIPA (National Income and Product Accounts)\n",
    "\n",
    "The NIPA dataset contains data from the standard set of NIPA tables as published in the Survey of Current Business. Availability of updated NIPA data follows the BEA News Release schedule as posted on the BEA web site. The NIPA dataset may be unavailable for a few minutes preceding the monthly GDP release while data is being updated (as it is for all other methods of acquiring newly released data). "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "meta_data = pybea.get_parameter_list(USER_ID, DataSetName='NIPA')\n",
    "meta_data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "meta_data = pybea.get_parameter_values(USER_ID,\n",
    "                                       DataSetName='NIPA',\n",
    "                                       ParameterName='TableID')\n",
    "meta_data"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# NIUnderlyingDetail (National Income and Product Accounts)\n",
    "\n",
    "The NIUnderlyingDetail dataset contains detailed estimate data from underlying NIPA series that appear in the national income and product account (NIPA) tables as published in the Survey of Current Business."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Fixed Assets\n",
    "\n",
    "The FixedAssets dataset contains data from the standard set of Fixed Assets tables as published online. "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "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.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 1
}

{'fraction_non_alphanumeric': 0.18779093845771555, 'fraction_numerical': 0.04441315331731964, 'mean_word_length': 1.2649707339036471, 'pattern_counts': {'":': 347, '<': 1251, '<?xml version=': 0, '>': 1251, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 123, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5597731', 'n_tokens_mistral': 22682, 'n_tokens_neox': 20868, 'n_words': 3990}