Created
August 2, 2020 17:43
-
-
Save rchardptrsn/4d47ae4597cd1fb1ff8650f9df97ff22 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import pandas as pd | |
| import blspandas | |
| import api_key | |
| import requests | |
| import json | |
| # Pull a list of state fips Ids. | |
| bls_fips = blspandas.get_state_fips() | |
| # Create a dictionary of BLS query Ids and States | |
| # Split out to two dicts, one for each half (25) of the 50 states/territories | |
| bls_dict1, bls_dict2 = blspandas.get_bls_id_dicts(bls_fips,'LAUST','0000000000003') | |
| # API key in config.py which contains: bls_key = 'key' | |
| key = '?registrationkey={}'.format(api_key.bls_key) | |
| # Query the BLS API using batches - | |
| query1 = blspandas.query_bls(bls_dict1,key) | |
| query2 = blspandas.query_bls(bls_dict2,key) | |
| # Combine the queries horizontally | |
| combined_queries = pd.concat([query1,query2],axis=1).reset_index().rename(columns={'index': 'Date'}) | |
| # Clean the dataframe and melt to vertical format | |
| df = blspandas.clean_bls_data(combined_queries) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment