US Macroeconomic Data Explorer | Job Payrolls

Job Payrolls


A look at job creation, according to the US Bureau of Labor Statistics.

In [1]:
import pandas as pd
import altair as alt
import numpy as np
import re
from IPython.core.display import display, HTML

seriesNames = pd.read_html('http://www.bls.gov/webapps/legacy/cesbtab1.htm')[0]['Industry']

from urllib.request import urlopen

data = 'series_id=CEU0000000001&series_id=CEU0500000001&series_id=CEU0600000001&series_id=CEU1000000001&series_id=CEU1011330001&series_id=CEU1021000001&series_id=CEU1021100001&series_id=CEU1021200001&series_id=CEU1021210001&series_id=CEU1021220001&series_id=CEU1021230001&series_id=CEU1021300001&series_id=CEU2000000001&series_id=CEU2023600001&series_id=CEU2023610001&series_id=CEU2023620001&series_id=CEU2023700001&series_id=CEU2023800001&series_id=CEU2023800101&series_id=CEU2023800201&series_id=CEU3000000001&series_id=CEU3100000001&series_id=CEU3132100001&series_id=CEU3132700001&series_id=CEU3133100001&series_id=CEU3133200001&series_id=CEU3133300001&series_id=CEU3133400001&series_id=CEU3133410001&series_id=CEU3133420001&series_id=CEU3133440001&series_id=CEU3133450001&series_id=CEU3133460001&series_id=CEU3133500001&series_id=CEU3133600001&series_id=CEU3133600101&series_id=CEU3133700001&series_id=CEU3133900001&series_id=CEU3200000001&series_id=CEU3231100001&series_id=CEU3231300001&series_id=CEU3231400001&series_id=CEU3231500001&series_id=CEU3232200001&series_id=CEU3232300001&series_id=CEU3232400001&series_id=CEU3232500001&series_id=CEU3232600001&series_id=CEU3232900001&series_id=CEU0800000001&series_id=CEU4000000001&series_id=CEU4142000001&series_id=CEU4142300001&series_id=CEU4142400001&series_id=CEU4142500001&series_id=CEU4200000001&series_id=CEU4244100001&series_id=CEU4244110001&series_id=CEU4244120001&series_id=CEU4244130001&series_id=CEU4244200001&series_id=CEU4244300001&series_id=CEU4244400001&series_id=CEU4244500001&series_id=CEU4244600001&series_id=CEU4244700001&series_id=CEU4244800001&series_id=CEU4245100001&series_id=CEU4245200001&series_id=CEU4245220001&series_id=CEU4245230001&series_id=CEU4245300001&series_id=CEU4245400001&series_id=CEU4300000001&series_id=CEU4348100001&series_id=CEU4348200001&series_id=CEU4348300001&series_id=CEU4348400001&series_id=CEU4348500001&series_id=CEU4348600001&series_id=CEU4348700001&series_id=CEU4348800001&series_id=CEU4349200001&series_id=CEU4349300001&series_id=CEU4422000001&series_id=CEU5000000001&series_id=CEU5051100001&series_id=CEU5051200001&series_id=CEU5051500001&series_id=CEU5051700001&series_id=CEU5051800001&series_id=CEU5051900001&series_id=CEU5500000001&series_id=CEU5552000001&series_id=CEU5552100001&series_id=CEU5552200001&series_id=CEU5552210001&series_id=CEU5552211001&series_id=CEU5552220001&series_id=CEU5552230001&series_id=CEU5552300001&series_id=CEU5552400001&series_id=CEU5553000001&series_id=CEU5553100001&series_id=CEU5553200001&series_id=CEU5553300001&series_id=CEU6000000001&series_id=CEU6054000001&series_id=CEU6054110001&series_id=CEU6054120001&series_id=CEU6054130001&series_id=CEU6054140001&series_id=CEU6054150001&series_id=CEU6054160001&series_id=CEU6054170001&series_id=CEU6054180001&series_id=CEU6054190001&series_id=CEU6055000001&series_id=CEU6056000001&series_id=CEU6056100001&series_id=CEU6056110001&series_id=CEU6056120001&series_id=CEU6056130001&series_id=CEU6056132001&series_id=CEU6056140001&series_id=CEU6056150001&series_id=CEU6056160001&series_id=CEU6056170001&series_id=CEU6056190001&series_id=CEU6056200001&series_id=CEU6500000001&series_id=CEU6561000001&series_id=CEU6562000001&series_id=CEU6562000101&series_id=CEU6562100001&series_id=CEU6562110001&series_id=CEU6562120001&series_id=CEU6562130001&series_id=CEU6562140001&series_id=CEU6562150001&series_id=CEU6562160001&series_id=CEU6562190001&series_id=CEU6562200001&series_id=CEU6562300001&series_id=CEU6562310001&series_id=CEU6562320001&series_id=CEU6562330001&series_id=CEU6562390001&series_id=CEU6562400001&series_id=CEU6562410001&series_id=CEU6562420001&series_id=CEU6562430001&series_id=CEU6562440001&series_id=CEU7000000001&series_id=CEU7071000001&series_id=CEU7071100001&series_id=CEU7071200001&series_id=CEU7071300001&series_id=CEU7072000001&series_id=CEU7072100001&series_id=CEU7072200001&series_id=CEU8000000001&series_id=CEU8081100001&series_id=CEU8081200001&series_id=CEU8081300001&series_id=CEU9000000001&series_id=CEU9091000001&series_id=CEU9091100001&series_id=CEU9091912001&series_id=CEU9092000001&series_id=CEU9092161101&series_id=CEU9092200001&series_id=CEU9093000001&series_id=CEU9093161101&series_id=CEU9093200001&survey=lf&htmlpage=cesbtab1.htm&format=&html_tables=&delimiter=&catalog=&print_line_length=&lines_per_page=&row_stub_key=&year=&date=&net_change_start=&net_change_end=&percent_change_start=&percent_change_end='

res = urlopen('https://data.bls.gov/pdq/SurveyOutputServlet', data.encode('ascii')).read()

tables = pd.read_html(res)[1:-1]

# Filter to valid data only
tables = [t for t in tables if t.columns[0] == "Year"]

combined = pd.DataFrame()

for n, t in enumerate(tables):
    #print(t)
    try:
        tmp = tables[n].iloc[:-1, :].melt('Year')
    except KeyError:
        continue
        
    tmp['dt'] = pd.to_datetime(tmp['Year'] + '-' + tmp['variable'], format='%Y-%b')
    
    tmp['value'] = tmp['value'].apply(lambda s: s if isinstance(s, float) else float(s.replace('(P)', '')))

    try:
        combined = pd.concat([combined, tmp.set_index('dt')['value'].rename(seriesNames.iloc[n]).dropna()], axis=1)
    except IndexError:
        continue
        
#combined.sort_index().tail()
/tmp/ipykernel_4350/394704797.py:5: DeprecationWarning: Importing display from IPython.core.display is deprecated since IPython 7.14, please import from IPython display
  from IPython.core.display import display, HTML
In [2]:
def yoyChartFor(combined, series='Total private'):
    yoyPriv = combined[series].sort_index()\
                              .pct_change(periods=12)\
                              .apply(lambda v: v*100 if isinstance(v, float) else np.nan)\
                              .reset_index().copy()

    yoyPriv = yoyPriv.replace(np.inf, np.nan).dropna()
    
    if (0 in yoyPriv.columns):
        return None
    
    if '.' in yoyPriv.columns.to_list()[-1]:
        series = series.replace(".", "")
        yoyPriv.columns = ['index', series]
        
    if ' ' in yoyPriv.columns.to_list()[-1]:
        series = series.replace(" ", "-")
        yoyPriv.columns = ['index', series]
    
    return yoyPriv.iloc[-1:, 1].values[0], alt.Chart(yoyPriv).mark_bar(width=3).encode(
        alt.X('index:T', axis=alt.Axis(title='')),
        alt.Y(f'{series}:Q', axis=alt.Axis(title='Year over Year Growth [%]')),
        color=alt.condition(f"datum['{series}'] < 0",
            alt.value('red'),
            alt.value('royalblue')
        ),
        tooltip=[alt.Tooltip('index:T'), alt.Tooltip(f'{series}:Q', format=',.02f', title='YoY % Change')]
    ).properties(
        title=f'BLS Nonfarm Payroll Growth ({series} sector)',
        width=750,
        height=400
    )
In [3]:
l, c = yoyChartFor(combined)
c.save('labor.png')
c.display()
In [4]:
charts = sorted([yoyChartFor(combined, c) for c in combined.columns.tolist()], key=lambda v: v[0] if v else 0)

isFirstDecliner = True
display(HTML("<h2 id='growth'>{}</h2>".format("Growing Sectors")))
display(HTML("<p>{}</p><br>".format("(largest growers first)")))
for v in reversed(charts):
    if v is None: continue
        
    if v[0] < 0 and isFirstDecliner:
        isFirstDecliner = False
        display(HTML("<h2 id='decline'>{}</h2>".format("Declining Sectors")))
        display(HTML("<p>{}</p><br>".format("(smallest decliners first)")))

    display(HTML("<h4>{}</h4><br>".format(v[1].to_dict()['title'])))
    v[1].properties(title='').display()

Growing Sectors

(largest growers first)


BLS Nonfarm Payroll Growth (Gasoline-stations-and-fuel-dealers sector)


BLS Nonfarm Payroll Growth (Support-activities-for-mining sector)


BLS Nonfarm Payroll Growth (Pipeline-transportation sector)


BLS Nonfarm Payroll Growth (Skilled-nursing-care-facilities sector)


BLS Nonfarm Payroll Growth (Furniture-and-home-furnishings-retailers sector)


BLS Nonfarm Payroll Growth (Other-residential-care-facilities sector)


BLS Nonfarm Payroll Growth (Hospitals sector)


BLS Nonfarm Payroll Growth (Mining,-quarrying,-and-oil-and-gas-extraction sector)


BLS Nonfarm Payroll Growth (Residential-intellectual-and-developmental-disability,-mental-health,-and-substance-abuse-facilities sector)


BLS Nonfarm Payroll Growth (Warehouse-clubs,-supercenters,-and-other-general-merchandise-retailers sector)


BLS Nonfarm Payroll Growth (Nursing-and-residential-care-facilities sector)


BLS Nonfarm Payroll Growth (Mining-and-logging sector)


BLS Nonfarm Payroll Growth (Legal-services sector)


BLS Nonfarm Payroll Growth (Transit-and-ground-passenger-transportation sector)


BLS Nonfarm Payroll Growth (Management,-scientific,-and-technical-consulting-services sector)


BLS Nonfarm Payroll Growth (Activities-related-to-credit-intermediation sector)


BLS Nonfarm Payroll Growth (Ambulatory-health-care-services sector)


BLS Nonfarm Payroll Growth (Other-ambulatory-health-care-services sector)


BLS Nonfarm Payroll Growth (Outpatient-care-centers sector)


BLS Nonfarm Payroll Growth (Offices-of-other-health-practitioners sector)


BLS Nonfarm Payroll Growth (Continuing-care-retirement-communities-and-assisted-living-facilities-for-the-elderly sector)


BLS Nonfarm Payroll Growth (General-merchandise-retailers sector)


BLS Nonfarm Payroll Growth (Real-estate-and-rental-and-leasing sector)


BLS Nonfarm Payroll Growth (Offices-of-dentists sector)


BLS Nonfarm Payroll Growth (Social-assistance sector)


BLS Nonfarm Payroll Growth (Manufacturing-and-reproducing-magnetic-and-optical-media-and-audio-and-video-equipment-manufacturing sector)


BLS Nonfarm Payroll Growth (Accounting,-tax-preparation,-bookkeeping,-and-payroll-services sector)


BLS Nonfarm Payroll Growth (Insurance-carriers-and-related-activities sector)


BLS Nonfarm Payroll Growth (Rental-and-leasing-services sector)


BLS Nonfarm Payroll Growth (Transportation-equipment-manufacturing(1) sector)


BLS Nonfarm Payroll Growth (Home-health-care-services sector)


BLS Nonfarm Payroll Growth (Motor-vehicles-and-parts(2) sector)


BLS Nonfarm Payroll Growth (Other-support-services sector)


BLS Nonfarm Payroll Growth (Computer-and-peripheral-equipment-manufacturing sector)


BLS Nonfarm Payroll Growth (Other-professional,-scientific,-and-technical-services sector)


BLS Nonfarm Payroll Growth (Travel-arrangement-and-reservation-services sector)


BLS Nonfarm Payroll Growth (Nondepository-credit-intermediation sector)


BLS Nonfarm Payroll Growth (Vocational-rehabilitation-services sector)


BLS Nonfarm Payroll Growth (Private-educational-services sector)


BLS Nonfarm Payroll Growth (Health-care(3) sector)


BLS Nonfarm Payroll Growth (Waste-management-and-remediation-services sector)


BLS Nonfarm Payroll Growth (Administrative-and-support-services sector)


BLS Nonfarm Payroll Growth (Nonresidential-building-construction sector)


BLS Nonfarm Payroll Growth (Administrative-and-support-and-waste-management-and-remediation-services sector)


BLS Nonfarm Payroll Growth (Office-administrative-services sector)


BLS Nonfarm Payroll Growth (Oil-and-gas-extraction sector)


BLS Nonfarm Payroll Growth (Heavy-and-civil-engineering-construction sector)


BLS Nonfarm Payroll Growth (Nonmetallic-mineral-product-manufacturing sector)


BLS Nonfarm Payroll Growth (Coal-mining sector)


BLS Nonfarm Payroll Growth (Nonmetallic-mineral-mining-and-quarrying sector)


BLS Nonfarm Payroll Growth (Health-care-and-social-assistance sector)


BLS Nonfarm Payroll Growth (Broadcasting-and-content-providers sector)


BLS Nonfarm Payroll Growth (Clothing,-clothing-accessories,-shoe,-and-jewelry-retailers sector)


BLS Nonfarm Payroll Growth (Credit-intermediation-and-related-activities sector)


BLS Nonfarm Payroll Growth (Management-of-companies-and-enterprises sector)


BLS Nonfarm Payroll Growth (Mining-(except-oil-and-gas) sector)


BLS Nonfarm Payroll Growth (Facilities-support-services sector)


BLS Nonfarm Payroll Growth (Wholesale-trade-agents-and-brokers sector)


BLS Nonfarm Payroll Growth (Community-food-and-housing,-and-emergency-and-other-relief-services sector)


BLS Nonfarm Payroll Growth (Employment-services(1) sector)


BLS Nonfarm Payroll Growth (Commercial-banking sector)


BLS Nonfarm Payroll Growth (Private-education-and-health-services sector)


BLS Nonfarm Payroll Growth (Investigation-and-security-services sector)


BLS Nonfarm Payroll Growth (Automotive-parts,-accessories,-and-tire-retailers sector)


BLS Nonfarm Payroll Growth (Beverage,-tobacco,-and-leather-and-allied-product-manufacturing sector)


BLS Nonfarm Payroll Growth (Couriers-and-messengers sector)


BLS Nonfarm Payroll Growth (Metal-ore-mining sector)


BLS Nonfarm Payroll Growth (Construction-of-buildings sector)


BLS Nonfarm Payroll Growth (Accommodation-and-food-services sector)


BLS Nonfarm Payroll Growth (Medical-and-diagnostic-laboratories sector)


BLS Nonfarm Payroll Growth (Advertising,-public-relations,-and-related-services sector)


BLS Nonfarm Payroll Growth (Individual-and-family-services sector)


BLS Nonfarm Payroll Growth (Nonresidential-specialty-trade-contractors sector)


BLS Nonfarm Payroll Growth (Offices-of-physicians sector)


BLS Nonfarm Payroll Growth (Machinery-manufacturing sector)


BLS Nonfarm Payroll Growth (Department-stores sector)


BLS Nonfarm Payroll Growth (Temporary-help-services sector)


BLS Nonfarm Payroll Growth (Scientific-research-and-development-services sector)


BLS Nonfarm Payroll Growth (Food-manufacturing sector)


BLS Nonfarm Payroll Growth (Private-service-providing sector)


BLS Nonfarm Payroll Growth (Total-private sector)


BLS Nonfarm Payroll Growth (Financial-activities sector)


BLS Nonfarm Payroll Growth (Total-nonfarm sector)


BLS Nonfarm Payroll Growth (Merchant-wholesalers,-durable-goods sector)


BLS Nonfarm Payroll Growth (Semiconductor-and-other-electronic-component-manufacturing sector)


BLS Nonfarm Payroll Growth (Construction sector)


BLS Nonfarm Payroll Growth (Computing-infrastructure-providers,-data-processing,-web-hosting,-and-related-services sector)


BLS Nonfarm Payroll Growth (Amusement,-gambling,-and-recreation-industries sector)


BLS Nonfarm Payroll Growth (Goods-producing sector)


BLS Nonfarm Payroll Growth (Logging sector)


BLS Nonfarm Payroll Growth (Durable-goods sector)


BLS Nonfarm Payroll Growth (Food-services-and-drinking-places sector)


BLS Nonfarm Payroll Growth (Electronics-and-appliance-retailers sector)


BLS Nonfarm Payroll Growth (Web-search-portals,-libraries,-archives,-and-other-information-services sector)


BLS Nonfarm Payroll Growth (Wholesale-trade sector)


BLS Nonfarm Payroll Growth (Securities,-commodity-contracts,-funds,-trusts,-and-other-financial-vehicles,-investments,-and-related-activities sector)


BLS Nonfarm Payroll Growth (Water-transportation sector)


BLS Nonfarm Payroll Growth (Primary-metal-manufacturing sector)


BLS Nonfarm Payroll Growth (Leisure-and-hospitality sector)


BLS Nonfarm Payroll Growth (Business-support-services sector)


BLS Nonfarm Payroll Growth (Computer-and-electronic-product-manufacturing sector)


BLS Nonfarm Payroll Growth (Residential-building-construction sector)


BLS Nonfarm Payroll Growth (Other-services sector)


BLS Nonfarm Payroll Growth (Rail-transportation sector)


BLS Nonfarm Payroll Growth (Monetary-authorities-central-bank sector)


BLS Nonfarm Payroll Growth (Manufacturing sector)


BLS Nonfarm Payroll Growth (Specialty-trade-contractors sector)


BLS Nonfarm Payroll Growth (Real-estate sector)


BLS Nonfarm Payroll Growth (Furniture,-home-furnishings,-electronics,-and-appliance-retailers sector)


BLS Nonfarm Payroll Growth (Chemical-manufacturing sector)


BLS Nonfarm Payroll Growth (Child-care-services sector)


BLS Nonfarm Payroll Growth (Food-and-beverage-retailers sector)


BLS Nonfarm Payroll Growth (Performing-arts,-spectator-sports,-and-related-industries sector)


BLS Nonfarm Payroll Growth (Fabricated-metal-product-manufacturing sector)


BLS Nonfarm Payroll Growth (Utilities sector)


BLS Nonfarm Payroll Growth (Accommodation sector)


BLS Nonfarm Payroll Growth (Merchant-wholesalers,-nondurable-goods sector)


BLS Nonfarm Payroll Growth (Nondurable-goods sector)


BLS Nonfarm Payroll Growth (Lessors-of-nonfinancial-intangible-assets-(except-copyrighted-works) sector)


BLS Nonfarm Payroll Growth (Other-motor-vehicle-dealers sector)


BLS Nonfarm Payroll Growth (Printing-and-related-support-activities sector)


BLS Nonfarm Payroll Growth (Arts,-entertainment,-and-recreation sector)


BLS Nonfarm Payroll Growth (Petroleum-and-coal-products-manufacturing sector)


BLS Nonfarm Payroll Growth (Miscellaneous-manufacturing sector)


BLS Nonfarm Payroll Growth (Motor-vehicle-and-parts-dealers sector)


BLS Nonfarm Payroll Growth (Navigational,-measuring,-electromedical,-and-control-instruments-manufacturing sector)


BLS Nonfarm Payroll Growth (Telecommunications sector)


BLS Nonfarm Payroll Growth (Scenic-and-sightseeing-transportation sector)


BLS Nonfarm Payroll Growth (Trade,-transportation,-and-utilities sector)


BLS Nonfarm Payroll Growth (Residential-specialty-trade-contractors sector)


BLS Nonfarm Payroll Growth (Information sector)


BLS Nonfarm Payroll Growth (Apparel-manufacturing sector)


BLS Nonfarm Payroll Growth (Depository-credit-intermediation(1) sector)


BLS Nonfarm Payroll Growth (Electrical-equipment,-appliance,-and-component-manufacturing sector)


BLS Nonfarm Payroll Growth (Support-activities-for-transportation sector)


BLS Nonfarm Payroll Growth (Finance-and-insurance sector)


BLS Nonfarm Payroll Growth (Air-transportation sector)


BLS Nonfarm Payroll Growth (Professional-and-business-services sector)


BLS Nonfarm Payroll Growth (Professional,-scientific,-and-technical-services sector)


BLS Nonfarm Payroll Growth (Retail-trade sector)


Declining Sectors

(smallest decliners first)


BLS Nonfarm Payroll Growth (Automobile-dealers sector)


BLS Nonfarm Payroll Growth (Services-to-buildings-and-dwellings sector)


BLS Nonfarm Payroll Growth (Plastics-and-rubber-products-manufacturing sector)


BLS Nonfarm Payroll Growth (Museums,-historical-sites,-and-similar-institutions sector)


BLS Nonfarm Payroll Growth (Wood-product-manufacturing sector)


BLS Nonfarm Payroll Growth (Communications-equipment-manufacturing sector)


BLS Nonfarm Payroll Growth (Paper-manufacturing sector)


BLS Nonfarm Payroll Growth (Transportation-and-warehousing sector)


BLS Nonfarm Payroll Growth (Warehousing-and-storage sector)


BLS Nonfarm Payroll Growth (Sporting-goods,-hobby,-musical-instrument,-book,-and-miscellaneous-retailers sector)


BLS Nonfarm Payroll Growth (Truck-transportation sector)


BLS Nonfarm Payroll Growth (Textile-mills sector)


BLS Nonfarm Payroll Growth (Architectural,-engineering,-and-related-services sector)


BLS Nonfarm Payroll Growth (Building-material-and-garden-equipment-and-supplies-dealers sector)


BLS Nonfarm Payroll Growth (Textile-product-mills sector)


BLS Nonfarm Payroll Growth (Furniture-and-related-product-manufacturing sector)


BLS Nonfarm Payroll Growth (Specialized-design-services sector)


BLS Nonfarm Payroll Growth (Health-and-personal-care-retailers sector)


BLS Nonfarm Payroll Growth (Computer-systems-design-and-related-services sector)


BLS Nonfarm Payroll Growth (Motion-picture-and-sound-recording-industries sector)


BLS Nonfarm Payroll Growth (Publishing-industries sector)


In [ ]:
 

© kdunn926