How I picked out the year for peak employment in New York State by County

How I picked out the year for peak employment in New York State by County. πŸ—Ί

Just a few quick lines of Python code:

import pandas as pd

# by using RemoteZip (pip install remotezip) this speeds
# up downloads by only downloading the files in the zip file
# that we actually need from DOL
from remotezip import RemoteZip

dolzip='https://dol.ny.gov/statistics-lauszip'

# download & load only cities and counties
with RemoteZip(dolzip) as zip:
    df=pd.read_csv(zip.extract('laus_counties.txt'))
    df=df.append(pd.read_csv(zip.extract('laus_cities.txt')))

# get rid of double quotes in column names
df.columns = df.columns.str.replace('\"','')

# get rid of spaces in column names
df.columns=df.columns.str.replace(' ','')
# select year and county totals, create a pandas pivot table, then
# run idmax to the highest employment number for each county
df[((df['MONTH'] == 0) & (df['AREA'].str.contains('County')))].pivot(index='YEAR',columns='AREA',values='EMP').idxmax()

Leave a Reply

Your email address will not be published. Required fields are marked *