I hope that I can clearly explain what I'm trying to do here. I'm able to retrieve the series date and values through the Bureau of Labor Statistics(BLS) API data. https://www.bls.gov/
I want to now get the 1-year percent change for each value. I'm grateful for any help on this. XXXXX is where I put my registration ID, so I can access more than three years of data.
Here's the developer's page: https://www.bls.gov/developers/api_signature_v2.htm#parameters
base_url = 'https://api.bls.gov/publicAPI/v2/timeseries/data/'
series = {'id': 'CUSR0000SA0',
'name': 'Consumer Price Index - All Urban Consumers'}
data_url = '{}{}/?registrationkey=XXXXXXXXXXXXXXXXXX&startyear=2010&endyear=2022'.format(base_url, series['id'])
import requests
r = requests.get(data_url).json()
print('Status: ' + r['status'])
r = r['Results']['series'][0]['data']
print(r[0])
import pandas as pd
##M13 is annual year, which I'm skipping since I only want months 1-12
dates = ['{}{}'.format(i['period'], i['year']) for i in r if i['period'] < 'M13']
index = pd.to_datetime(dates)
data = {series['id']: [float(i['value']) for i in r if i['period'] < 'M13']}
df = pd.DataFrame(index=index, data=data).iloc[::-1]
I'm not sure how to write up retrieving calculations in my code. I tried "calculations: {[i['calculations'][0] for i in r if i['period'] < 'M13']}" but that is not right.