finds.readers.bea
Wrapper over BEA web api and data source files
Bureau of Economic Analysis: Input-Output Use Tables
BEA released initial results of the comprehensive update of the National Economic Accounts (NEAs), which include the National Income and Product Accounts (NIPAs) and the Industry Economic Accounts (IEAs), on September 28, 2023.
Copyright 2022, Terence Lim
MIT License
- class finds.readers.bea.BEA(rdb: RedisDB | None, userid: str, verbose: int = 1)[source]
Bases:
object
Class and methods to retrieve BEA web api and IOUse datasets
- Parameters:
rdb – Redis connection instance to cache data from BEA web site
userid – Register with BEA to get key for their web api
- Variables:
short_desc – Reference Series maps BEA industry to custom descriptions
params – Some common parameter sets for BEA web api
Examples:
>>> bea = BEA() >>> df = bea.get(**BEA.items['industries']) >>> sql.load_dataframe('gdpindustry', df, index_label=None, if_exists='replace') >>> df = bea.get(**BEA.items['ioUse'], year=2018)
- get(datasetname: str = '', parametername: str = '', cache_mode: str = 'rw', **kwargs) DataFrame [source]
Execute common BEA web api calls
- Parameters:
datasetname – Name of dataset to retrieve, e.g. ‘ioUse’
parametername – Parameter to retrieve, e.g. ‘TableID’
cache_mode – ‘r’ to try read from cache first, ‘w’ to write to cache
kwargs – Additional parameters, such as tableid or year
Examples:
>>> datasetname='ioUse' >>> tableid=259 >>> year = 2017 >>> parametername = 'TableID' >>> bea.get() >>> bea.get(datasetname) >>> bea.get(datasetname, parametername=parametername) >>> bea.get('ioUse') >>> df = bea.get(datasetname='ioUse', tableid=259, year=2018) >>> df = bea.get(datasetname='GDPbyIndustry', parametername='Industry')
- read_ioUse(year: int, vintage: int = 0, cache_mode: str = 'rw') DataFrame [source]
Load ioUse table from BEA web api (or xls if early vintage)
- Parameters:
year – Year of IO-Use to load
vintage – Year of sectoring; allows different eras to be compared
cache_mode – ‘r’ to try read from cache first, ‘w’ to write to cache
- Returns:
DataFrame in stacked form, flows amounts in ‘datavalue’ column, and columns ‘rowcode’, ‘colcode’ label maker and user industry
Notes:
rows, column codes that start with (‘T’,’U’,’V’,’Other’) are dropped
‘F’: final_use,
‘G’: govt,
‘T’: total&tax,
‘U’: used,
‘V’:value_added,
‘O’:imports
generally, should drop = (‘F’,’T’,’U’,’V’,’Other’)
Examples:
>>> bea=BEA() >>> data = bea.read_ioUse(1996) >>> sql.load_dataframe('ioUse', data, index_label=None, if_exists='replace') >>> data = sql.select('ioUse', where={'year': 2017, 'tableid' : 259}) >>> df = data.pivot(index='rowcode', columns='colcode', values='datavalue')
- read_ioUse_xls(year: int, cache_mode: str = 'rw', source: str | None = None) DataFrame [source]
Helper to load a year’s ioUSE table from vintage xls on website
- Parameters:
year – year of IoUse to fetch
cache_mode – ‘r’ to try read from cache first, ‘w’ to write to cache
source – url or filename to read from
- static sectoring(year: int, source: str = '')[source]
Returns BEA sector definitions, based on naics, from xls on BEA website
- Parameters:
year – Year of historical BEA scheme, in {1997, 1964, 1947}
source – Source url or local file
Notes:
https://apps.bea.gov/industry/xls/io-annual/ - IOUse_Before_Redefinitions_PRO_1947-1962_Summary.xlsx - Use_SUT_Framework_2007_2012_DET.xlsx
Replace “HS” “ORE” with “531”
- params = {'gdpindustry': {'datasetname': 'GDPbyIndustry', 'index': 'key', 'parametername': 'Industry'}, 'ioUse': {'datasetname': 'inputoutput', 'tableid': 259}}
- short_desc = 11 Agriculture 111CA Farms 113FF Forestry,fishing 21 Mining 211 Oil, gas ... GFGN Nondefense GFE Federal enterprises GSL State local GSLG State local general GSLE State local enterprises Name: label, Length: 95, dtype: object