I'm trying to get pandasdmx (v0.9, using pandas 0.23 and python 3.7) up and running for some IMF data requests. In particular, accessing the BOP (BPM6) series.
I feel like I'm truly missing something here, as I suspect the IMF data structures are a bit more complex than the ECB data example in the docs and I'm at a loss on how to proceed. The basic code I'm trying to use is:
#!/usr/local/bin/python
import pandas as pd
import pandasdmx
countries = {'Australia': 'AU', 'Austria': 'OE', 'Belgium': 'BE', 'Canada': 'CA', 'Hong Kong': 'HK', 'Denmark': 'DK', 'Euro area': 'EM', 'Finland': 'FN', 'France': 'FR', 'Germany': 'BD', 'Greece': 'GR
', 'Ireland': 'IR', 'Israel': 'IS', 'Italy': 'IT', 'Japan': 'JP', 'Netherlands': 'NL', 'New Zealand': 'NZ', 'Norway': 'NW', 'Portugal': 'PT', 'Singapore': 'SG', 'Spain': 'ES', 'Sweden': 'SE', 'Switzer
land': 'CH', 'United Kingdom': 'UK', 'United States': 'US'}
imf = pandasdmx.Request('IMF_SDMXCENTRAL')
bop_flow = imf.dataflow('BOP_BPM6')dsd = bop_flow.dataflow.BOP_BPM6.structure()
# Get a list of regions/areas from country list
areas = bop_flow.write().codelist.loc['CL_REF_AREA']areas = areas[areas['name'].isin(countries.keys())]
# Get a list of indicators for each of the specific BOP series of interest
codes = bop_flow.write().codelist.loc['CL_INDICATOR']codes = codes[codes['name'].str.contains('Balance of Payments', case=False) & codes['name'].str.contains('Financial Account', case=False) & codes['name'].str.contains('Portfolio Investment', case=False) & codes['name'].str.contains('Net acquisition of financial assets', case=False) & codes['name'].str.contains('US Dollars', case=False)]codes = codes[codes.index.str.contains('BP6')]
# Pull down data into a dataframe
for code in list(codes.index):
resp = imf.data(resource_id='BOP_BPM6', key={'INDICATOR': code, 'REF_AREA': list(areas)}, dsd=dsd)
data = resp.data
quarterly = (s for s in data.series if s.key.FREQ == 'D')
df = data_response.write(quarterly)
Any help would be appreciated!